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の「visit」を含むページを取得する必要があります。RSpecとCapybaraに関するこの質問を参照してください。

于 2012-09-18T08:30:54.770 に答える