2012-02-10 34 views
1

我想驗證Sinatra應用程序的初始頁面的開始,但我努力獲得測試框架的工作。谷歌搜索建議我添加cucumber/rails/rspec或類似的,但我真的需要在不使用Rails時添加與軌道相關的庫嗎?未定義的方法`have_content'使用黃瓜/水豚/ sinatra

這裏是我的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) 

和我的ENV

require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'survey_tool') 

require 'capybara/cucumber' 
require 'capybara/rspec' 
Capybara.app = Sinatra::Application 
Sinatra::Application.set :environment, :test 

我收到的錯誤是

方案:啓動調查#功能/ start_a_survey.feature:4 一個房間需要被調查#特性/ step_definitions/start_a_survey_steps.rb:1 當我開始調查#特點/step_definitions/start_a_survey_steps.rb:5 然後,系統會提示我調查摘要#特徵/ 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

我認爲這裏的問題在於你沒有包含rspec期望值。水豚節點有一個has_content?方法。

這是rspec的期望,當給出'have_content'作爲參數時,調用'has_content?'在目標上。因此,請嘗試將'rspec-expectations'添加到您的Gemfile中,然後將require 'rspec/expectations'添加到您的模塊中。