我正在尝试验证Sinatra应用程序的初始页面的开始,但我正在努力让测试框架正常工作。谷歌搜索建议我添加cucumber / rails / rspec或类似,但我真的需要在不使用Rails时添加rails相关的库?
这是我的Gemfile
source :rubygems
gem 'sinatra', '1.3.1'
gem 'json', '1.6.3'
group :test do
gem 'rspec', '2.7.0'
gem 'cucumber', '1.1.3'
gem 'capybara', '1.1.2'
gem 'rack-test', '0.6.1'
end
和我的步骤:
Given /^a room needs to be surveyed$/ do
end
When /^I start a survey$/ do
survey_tool.start_a_survey
end
Then /^the system will prompt me for a survey summary$/ do
survey_tool.validate_start_a_survey_page
end
和我的世界扩展
module KnowsTheUserInterface
class UserInterface
include Capybara::DSL
def start_a_survey()
visit '/start_a_survey'
end
def validate_start_a_survey_page ()
page.should have_content('Welcome')
end
end
def survey_tool
@survey_tool ||=UserInterface.new
end
end
World(KnowsTheUserInterface)
和我的环境
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'survey_tool')
require 'capybara/cucumber'
require 'capybara/rspec'
Capybara.app = Sinatra::Application
Sinatra::Application.set :environment, :test
我收到的错误是
场景:开始调查#features / start_a_survey.feature:4
鉴于需要调查房间#features / step_definitions / start_a_survey_steps.rb:1
当我开始调查时#features / step_definitions / start_a_survey_steps.rb:5
然后系统会提示我输入调查摘要#features / step_definitions / start_a_survey_steps.rb:9
未定义的方法have_content' for #<KnowsTheUserInterface::UserInterface:0x007f910465fc38> (NoMethodError)
./features/support/world_extensions.rb:10:in
validate_start_a_survey_page'
./features/step_definitions/start_a_survey_steps.rb:10:in /^the system will prompt me for a survey summary$/'
features/start_a_survey.feature:7:in
然后系统会提示我提供调查摘要'
答案 0 :(得分:0)
我认为这里的问题是你没有包括rspec期望。 Capybara节点具有has_content?
方法。
rspec期望当'has_content'作为参数时,调用'has_content?'在目标上。
因此,请尝试将“rspec-expectations”添加到您的Gemfile中,并将require 'rspec/expectations'
添加到您的模块中。