1

我收到了这些 Capybara 错误(它们几乎都一样)并且不知道我做错了什么。

我的规格是:

红宝石版本:1.9.2p320

导轨版本:3.2.13

Rspec:2.11.1

电脑:Macbook Pro OS X Mountain Lion

错误

8) User pages profile page follow/unfollow buttons following a user should increment the followed user count
     Failure/Error: click_button "Follow"
     Capybara::ElementNotFound:
       no button with value or id or text 'Follow' found
     # (eval):2:in `click_button'
     # ./spec/requests/user_pages_spec.rb:101:in `block (6 levels) in <top (required)>'
     # ./spec/requests/user_pages_spec.rb:100:in `block (5 levels) in <top (required)>'

  9) User pages profile page follow/unfollow buttons following a user should increment the other user's followers count
     Failure/Error: click_button "Follow"
     Capybara::ElementNotFound:
       no button with value or id or text 'Follow' found
     # (eval):2:in `click_button'
     # ./spec/requests/user_pages_spec.rb:107:in `block (6 levels) in <top (required)>'
     # ./spec/requests/user_pages_spec.rb:106:in `block (5 levels) in <top (required)>'

  10) User pages profile page follow/unfollow buttons following a user toggling the button 
     Failure/Error: before { click_button "Follow" }
     Capybara::ElementNotFound:
       no button with value or id or text 'Follow' found
     # (eval):2:in `click_button'
     # ./spec/requests/user_pages_spec.rb:112:in `block (6 levels) in <top (required)>'

  11) User pages profile page follow/unfollow buttons unfollowing a user should decrement the followed user count
     Failure/Error: click_button "Unfollow"
     Capybara::ElementNotFound:
       no button with value or id or text 'Unfollow' found
     # (eval):2:in `click_button'
     # ./spec/requests/user_pages_spec.rb:125:in `block (6 levels) in <top (required)>'
     # ./spec/requests/user_pages_spec.rb:124:in `block (5 levels) in <top (required)>'

  12) User pages profile page follow/unfollow buttons unfollowing a user should decrement the other user's followers count
     Failure/Error: click_button "Unfollow"
     Capybara::ElementNotFound:
       no button with value or id or text 'Unfollow' found
     # (eval):2:in `click_button'
     # ./spec/requests/user_pages_spec.rb:131:in `block (6 levels) in <top (required)>'
     # ./spec/requests/user_pages_spec.rb:130:in `block (5 levels) in <top (required)>'

  13) User pages profile page follow/unfollow buttons unfollowing a user toggling the button 
     Failure/Error: before { click_button "Unfollow" }
     Capybara::ElementNotFound:
       no button with value or id or text 'Unfollow' found
     # (eval):2:in `click_button'
     # ./spec/requests/user_pages_spec.rb:136:in `block (6 levels) in <top (required)>'

user_pages_spec.rb

describe "follow/unfollow buttons" do
      let(:other_user) { FactoryGirl.create(:user) }
      before { sign_in user }

      describe "following a user" do
        before { visit user_path(other_user) }

        it "should increment the followed user count" do
          expect do
            click_button "Follow"
          end.to change(user.followed_users, :count).by(1)
        end

        it "should increment the other user's followers count" do
          expect do
            click_button "Follow"
          end.to change(other_user.followers, :count).by(1)
        end

        describe "toggling the button" do
          before { click_button "Follow" }
          it { should have_selector('input', value: 'Unfollow') }
        end
      end

      describe "unfollowing a user" do
        before do
          user.follow!(other_user)
          visit user_path(other_user)
        end

        it "should decrement the followed user count" do
          expect do
            click_button "Unfollow"
          end.to change(user.followed_users, :count).by(-1)
        end

        it "should decrement the other user's followers count" do
          expect do
            click_button "Unfollow"
          end.to change(other_user.followers, :count).by(-1)
        end

        describe "toggling the button" do
          before { click_button "Unfollow" }
          it { should have_selector('input', value: 'Follow') }
        end
      end
    end
4

1 回答 1

1

正如错误消息报告的那样,您没有带有文本或 ID“关注”的按钮。我已经看到这种情况发生在一个假装是按钮的锚实际上确实存在标题为“Follow”的情况下,但 Capybara 希望看到一个带有该文本的实际按钮。

于 2013-08-14T19:30:18.503 回答