このカスタムステップが欲しいです:
Then I should see the link 'foo'
そして彼の反対:
But I should not see the link 'foo'
このページでは、次のようなものを使用できます。
lorem foo bar
または代わりに
lorem <a href=''>foo</a> bar
'foo'がリンクである場合とそうでない場合をテストする必要があります。ありがとうございました。
このカスタムステップが欲しいです:
Then I should see the link 'foo'
そして彼の反対:
But I should not see the link 'foo'
このページでは、次のようなものを使用できます。
lorem foo bar
または代わりに
lorem <a href=''>foo</a> bar
'foo'がリンクである場合とそうでない場合をテストする必要があります。ありがとうございました。
このようなものを試してください(私はそれを実行しようとしたことがないので、マイナーな調整が必要になる可能性があります):
Then /^I should see the link "([^\"]*)"$/ do |linked_text|
# AFAIK this raises an exception if the link is not found
find_link(linked_text)
end
Then /^I should not see the link "([^\"]*)"$/ do |linked_text|
begin
find_link(linked_text)
raise "Oh no, #{linked_text} is a link!"
rescue
# cool, the text is not a link
end
end
Webrat
これを行う(または少なくとも非常に類似している)事前定義されたステップがすでにあります。からweb_steps.rb
Then /^(?:|I )should see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
within(selector) do |content|
regexp = Regexp.new(regexp)
if defined?(Spec::Rails::Matchers)
content.should contain(regexp)
else
assert_match(regexp, content)
end
end
end
と
Then /^(?:|I )should not see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
within(selector) do |content|
if defined?(Spec::Rails::Matchers)
content.should_not contain(text)
else
hc = Webrat::Matchers::HasContent.new(text)
assert !hc.matches?(content), hc.negative_failure_message
end
end
end
これにxpathを使用すると、運が良くなる可能性があります。「// a / text()='foo'」のようなものを使用できます。webratのxpathを有効にする必要があります。ここhttp://www.opsb.co.uk/?p=165の表でxpathと同様のことを行うことについてのブログ投稿を書きました。これには、webratのxpathを有効にするために必要なコードが含まれています。 。
Then /^I should not see the link "([^\"]*)"$/ do |linked_text|
page.should_not have_css("a", :text => linked_text)
end
Then /^I should see the link "([^\"]*)"$/ do |linked_text|
page.should have_css("a", :text => linked_text)
end