0

このカスタムステップが欲しいです:

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'がリンクである場合とそうでない場合をテストする必要があります。ありがとうございました。

4

4 に答える 4

1

このようなものを試してください(私はそれを実行しようとしたことがないので、マイナーな調整が必要になる可能性があります):

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
于 2010-07-25T09:59:03.287 に答える
0

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
于 2010-07-23T10:58:24.677 に答える
0

これにxpathを使用すると、運が良くなる可能性があります。「// a / text()='foo'」のようなものを使用できます。webratのxpathを有効にする必要があります。ここhttp://www.opsb.co.uk/?p=165の表でxpathと同様のことを行うことについてのブログ投稿を書きました。これには、webratのxpathを有効にするために必要なコードが含まれています。 。

于 2010-07-25T22:57:18.583 に答える
0
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
于 2011-04-22T13:24:49.650 に答える