Rspec未定义的方法匹配?'错误

时间:2015-03-30 06:39:11

标签: ruby rspec selenium-webdriver

我尝试在Rspec中创建一个简单的测试套件。

require "selenium-webdriver"
require "rspec"

describe "User" do
  before (:all) do
    @ch = Selenium::WebDriver.for :chrome
  end
  it should "navigate to open2test" do
    @ch.get"http://www.open2test.org/"
  end
  it should "enter user name and email" do
    @ch.find_element(:id, "name").send_keys "jack"
    @ch.find_element(:id, "emailID").send_keys "jack@gmail.com"
  end
end

执行rspec file_name.rb时,我得到:

"rspec/expectations/handler.rb:50:in `block in handle_matcher': undefined method `matches?' for "navigate to open2test":String (NoMethodError)"

请更新我遗失的内容。

1 个答案:

答案 0 :(得分:2)

您正在调用itshould方法。

it should "navigate to open2test" do

在使用RSpec

时,您应该只在此处拨打it
it "should navigate to open2test" do
  # assert something
end

注意,其应具有Test::Unit

的以下语法
should "do something" do
  # assert something
end