1

我有以下集成步骤来检查一个.credits_count类和一个0 credits on it.

it "show credits available at the top." do 
  user = Factory.create(:user)
  login_as(user, :scope => :user)
  page.should have_selector('.credits_count', text: '0 credits')
end

问题是当.credits_count页面上带有文本时出现以下错误。

  Credits when user is non-enabled show user credits available at the top.
   Failure/Error: page.should have_selector('.credits_count', text: '0 credits')
   expected css ".credits_count" with text "0 credits" to return something
   # ./spec/requests/credits_spec.rb:12:in `block (3 levels) in <top (required)>'

知道为什么它没有看到.credits_count选择器吗?

视图布局如下所示。

# app/views/layouts/application.html.haml
- if current_user
  %li.credits_count
    = current_user.credits_count
    credits
4

1 回答 1

0

要使 Capybara 的“页面”工作,您需要使用 Capybara 的“访问”检索页面,请参阅有关 RSpec 和 Capybara 的这个问题

于 2012-09-18T08:30:54.770 回答