Rspec 未定义方法 'matches?' 错误

Rspec undefined method 'matches?' error

我试图在 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)"

请更新我遗漏的内容。

您同时调用了 itshould 方法。

it should "navigate to open2test" do

你应该只在这里调用 it 因为你正在使用 RSpec

it "should navigate to open2test" do
  # assert something
end

注意 Test::Unit

应该有以下语法
should "do something" do
  # assert something
end