1

奇怪的是,测试套件间歇性地通过或失败。我不知道为什么?我什么都没有改变,只是重新运行测试。有时是绿色,有时是红色。

为以下每个错误显示的错误消息:

Failure/Error: before { sign_in user }
     NoMethodError:
       undefined method `sign_in' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_2::Nested_2::Nested_1:0x0000000577cb58>


65 examples, 9 failures

Failed examples:

rspec ./spec/requests/user_pages_spec.rb:71 # User pages signup edit page 
rspec ./spec/requests/user_pages_spec.rb:73 # User pages signup edit page 
rspec ./spec/requests/user_pages_spec.rb:72 # User pages signup edit page 
rspec ./spec/requests/user_pages_spec.rb:97 # User pages signup edit with valid information 
rspec ./spec/requests/user_pages_spec.rb:96 # User pages signup edit with valid information 
rspec ./spec/requests/user_pages_spec.rb:95 # User pages signup edit with valid information 
rspec ./spec/requests/user_pages_spec.rb:94 # User pages signup edit with valid information 
rspec ./spec/requests/user_pages_spec.rb:93 # User pages signup edit with valid information 
rspec ./spec/requests/user_pages_spec.rb:79 # User pages signup edit with invalid information

user_pages_spec.rb

require 'spec_helper'

describe "User pages" do

  subject { page }

  describe "profile page" do
    let(:user) { FactoryGirl.create(:user) }
    before { visit user_path(user) }

    it { should have_content(user.name) }
    it { should have_title(user.name) }
  end

  describe "signup page" do
    before { visit signup_path }

    it { should have_content('Sign up') }
    it { should have_title(full_title('Sign up')) }
  end

  describe "signup" do

    before { visit signup_path }

    let(:submit) { "Create my account" }

    describe "with invalid information" do
      it "should not create a user" do
        expect { click_button submit }.not_to change(User, :count)
      end

      describe "after submission" do
        before { click_button submit }

        it { should have_title('Sign up') }
        it { should have_content('error') }
      end
    end

    describe "with valid information" do
      before do
        fill_in "Name",         with: "Example User"
        fill_in "Email",        with: "user@example.com"
        fill_in "Password",     with: "foobar"
        fill_in "Confirmation", with: "foobar"
      end

      it "should create a user" do
        expect { click_button submit }.to change(User, :count).by(1)
      end

      describe "after saving the user" do
        before { click_button submit }
        let(:user) { User.find_by(email: 'user@example.com') }

        it { should have_link('Sign out') }
        it { should have_title(user.name) }
        it { should have_selector('div.alert.alert-success', text: 'Welcome') }
      end
    end

    describe "edit" do
      let(:user) { FactoryGirl.create(:user) }
      before do
        sign_in user
        visit edit_user_path(user)
      end

      describe "page" do
        it { should have_content("Update your profile") }
        it { should have_title("Edit user") }
        it { should have_link('change', href: 'http://gravatar.com/emails') }
      end

      describe "with invalid information" do
        before { click_button "Save changes" }

        it { should have_content('error') }
      end

      describe "with valid information" do
        let(:new_name)  { "New Name" }
        let(:new_email) { "new@example.com" }
        before do
          fill_in "Name",             with: new_name
          fill_in "Email",            with: new_email
          fill_in "Password",         with: user.password
          fill_in "Confirm Password", with: user.password
          click_button "Save changes"
        end

        it { should have_title(new_name) }
        it { should have_selector('div.alert.alert-success') }
        it { should have_link('Sign out', href: signout_path) }
        specify { expect(user.reload.name).to  eq new_name }
        specify { expect(user.reload.email).to eq new_email }
      end
    end
  end
end
4

1 回答 1

0

我以某种方式从“spec/support/utilities.rb”顶部删除了“include ApplicationHelper”

于 2013-09-10T15:34:26.667 回答