Rails Tutorial メモvol.4

第９章でハマっているのでメモ
現在9.2.2

```
$ bundle exec rspec spec/requests/user_pages_spec.rb 
FFFFFFFF.............

Failures:

  1) UserPages edit with valid information  
     Failure/Error: fill_in "Name", with: new_name
     Capybara::ElementNotFound:
       Unable to find field "Name"
     # ./spec/requests/user_pages_spec.rb:91:in `block (4 levels) in <top (required)>'

  2) UserPages edit with valid information  
     Failure/Error: fill_in "Name", with: new_name
     Capybara::ElementNotFound:
       Unable to find field "Name"
     # ./spec/requests/user_pages_spec.rb:91:in `block (4 levels) in <top (required)>'

  3) UserPages edit with valid information  
     Failure/Error: fill_in "Name", with: new_name
     Capybara::ElementNotFound:
       Unable to find field "Name"
     # ./spec/requests/user_pages_spec.rb:91:in `block (4 levels) in <top (required)>'

  4) UserPages edit with valid information  
     Failure/Error: fill_in "Name", with: new_name
     Capybara::ElementNotFound:
       Unable to find field "Name"
     # ./spec/requests/user_pages_spec.rb:91:in `block (4 levels) in <top (required)>'

  5) UserPages edit with valid information  
     Failure/Error: fill_in "Name", with: new_name
     Capybara::ElementNotFound:
       Unable to find field "Name"
     # ./spec/requests/user_pages_spec.rb:91:in `block (4 levels) in <top (required)>'

  6) UserPages edit page 
     Failure/Error: it{should have_link('change',href:'http://gravatar.com/emails')}
       expected #has_link?("change", {:href=>"http://gravatar.com/emails"}) to return true, got false
     # ./spec/requests/user_pages_spec.rb:84:in `block (4 levels) in <top (required)>'

  7) UserPages edit page 
     Failure/Error: it{should have_title("Edit user")}
       expected #has_title?("Edit user") to return true, got false
     # ./spec/requests/user_pages_spec.rb:83:in `block (4 levels) in <top (required)>'

  8) UserPages edit page 
     Failure/Error: it{should have_content("Update your profile")}
       expected #has_content?("Update your profile") to return true, got false
     # ./spec/requests/user_pages_spec.rb:82:in `block (4 levels) in <top (required)>'

Finished in 1.41 seconds
21 examples, 8 failures

Failed examples:

rspec ./spec/requests/user_pages_spec.rb:98 # UserPages edit with valid information  
rspec ./spec/requests/user_pages_spec.rb:99 # UserPages edit with valid information  
rspec ./spec/requests/user_pages_spec.rb:100 # UserPages edit with valid information  
rspec ./spec/requests/user_pages_spec.rb:101 # UserPages edit with valid information  
rspec ./spec/requests/user_pages_spec.rb:102 # UserPages edit with valid information  
rspec ./spec/requests/user_pages_spec.rb:84 # UserPages edit page 
rspec ./spec/requests/user_pages_spec.rb:83 # UserPages edit page 
rspec ./spec/requests/user_pages_spec.rb:82 # UserPages edit page 
```

これがテストのエラー
前回からのテストから`user_pages_spec.rb`はいじってないはずだったんだが。。。

ちなみに

```ruby:user_pages_spec.rb
require 'spec_helper'

describe "UserPages" 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
    end

    describe "after submission" do
      before{click_button submit}

      it{should have_title('Sign up')}
      it{should have_content('error')}
    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_title(user.name)}
        it{should have_selector('div.alert-success',text:'Welcom')}
      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:'Welcom')}
      end
    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 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
```

とりあえず、Tutorialやっていく上で、テストはそのうち直るッていうのがちょくちょくあるし
時間もかなり取られているので置いておこう