如何使用某个单词进行测试是否与Cucumber有关?

时间:2010-07-23 09:54:22

标签: ruby-on-rails ruby cucumber bdd webrat

我想要这个自定义步骤:

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 个答案:

答案 0 :(得分:1)

答案 1 :(得分: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

答案 2 :(得分:0)

答案 3 :(得分: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