2012-02-13 17 views
0

の渡し:キュウリ/カピバラ機能は、常に私は、次のキュウリのシナリオを持っているに関係なく、ページコンテンツ

Background: 
    Given the following roles exist: 
    | id | name | 
    | 1 | janitor | 
    And the following users exist: 
    | username | password | email    | role_ids | 
    | janitor | Cleaning31 | [email protected] | 1  | 
    And I am logged in as "janitor" with password "Cleaning31" 
    And the following articles exist: 
    | id | title  | slug  | content  | 
    | 1 | Article One | article-one | Article one. | 

Scenario: Seeing link for deleting an article 
    When I view the article list 
    Then I should see the "Delete" link for article 1 

...そしてその最後のステップの定義:

Then /^I should (not)?see the "([^"]*)" link (?:in|under|for) article (\d+)$/ do |negation, content, article_id| 
    page.should have_selector("\#article_#{article_id}") do |article| 
    if negation 
     article.should_not have_css('a', text: content) 
    else 
     article.should have_css('a', text: content) 
    end 
    end 
end 

私は変更しても機能またはビューのいずれかで「削除する」という単語を「これは決して機能しません」に設定すると、その機能は常に通過します。ただしブラウザでは、「削除」リンクは、「管理者」ロールを持つユーザーの記事にのみ正しく表示されます。

キュウリの「私にそのページを見せて」と「回答を表示する」というのは、それらがすべきことを示唆する多数の記事にもかかわらず、定義されていないようです。 (My env.rb

他の機能は期待どおり機能するようです。私がどこでこれに間違っているのか誰にでも気付くことができますか?

答えて

3

あなたのテストではアサーションはありません。 article.should_not have_css('a', text: content)assert article.should_not have_css('a', text: content)に変更してください。

編集:

どのような結果が得られましたか?

element = page.find("\#article_#{article_id}") 
if negation 
     element.should_not have_css('a', text: content) 
else 
     element.should have_css('a', text: content) 
end 

あなたはfindヘルパを使用して、見つかった要素に対してアサーションを行う必要があります。あなたがブロックで利用できるものが「記事」であるのだろうか。

+0

ありがとうございますが、違いはありません。それは内容にかかわらずまだ通過します。他のすべての機能は同じスタイルで書かれ、正しく動作しますが、確かに.should_notと.should自体がアサーションですか? –

+0

私の答えに編集を加えました。 – socjopata

+0

それは、ありがとう!私はカピバラとWebratスタイルを使用しようとしていたのだろうか? –

関連する問題