我在Ruby 1.9.3,Padrino 0.10.7,rspec 2.11.0,capybara 2.0.2上设置的capybara和rspec发生了一些奇怪的事情。
一个基本的Padrino项目设置了haml和rspec (目前还没有自定义代码!)而不仅仅是加载一个"/“页面(我在下面的规范中通过"puts page.content”验证了它确实可以按预期呈现)。这是一个简单的规范。“假的”不存在,但“主页”does...note,当我放到控制台时,预期的真/假是正确的,但由于某些原因,匹配器没有正确地看到真/假。
到目前为止,我唯一的线索是在第二个规范中使用了应该have_content('Bogus'),它报告说Proc是预期的……
./spec/controller/hello_world_spec.rb
require 'spec_helper'
require 'capybara'
require 'capybara/rspec'
describe 'The HelloWorld App', :type => :feature do
context "per documentation" do
it "has bogus content" do
visit '/'
page.has_content?('Bogus')
end
it "does not have bogus content" do
visit '/'
page.should have_content("Bogus")
end
end
context "should tests" do
it "has bogus content" do
visit '/'
page.has_content?('Bogus').should == true
end
it "does not have bogus content" do
visit '/'
page.has_content?('Bogus').should == false
end
end
context "variables" do
it "has bogus content" do
visit '/'
result = page.has_content?('Bogus')
puts result
result.should == true
end
it "has Home content (expect TRUE!)" do
visit '/'
result = page.has_content?('Home')
puts result
result.should == true
end
it "does not have bogus content" do
visit '/'
result = page.has_content?('Bogus')
puts result
result.should == false
end
end
endspec_helper.rb
PADRINO_ENV = 'test' unless defined?(PADRINO_ENV)
require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
def app
##
# You can handle all padrino applications using instead:
Padrino.application
# Askme.tap do |app|
# end
end
RSpec.configure do |conf|
conf.include Rack::Test::Methods
Capybara.app = app
end输出:
11:40:57:website >> bundle exec rspec spec/app/controllers/hello_world_controller_spec.rb
WARNING: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.7.8
The HelloWorld App
per documentation
has bogus content
does not have bogus content (FAILED - 1)
should tests
has bogus content
does not have bogus content
variables
false
has bogus content
true
has Home content (expect TRUE!)
false
does not have bogus content
Failures:
1) The HelloWorld App per documentation does not have bogus content
Failure/Error: page.should have_content("Bogus")
TypeError:
wrong argument type Capybara::RSpecMatchers::HaveText (expected Proc)
# ./spec/app/controllers/hello_world_controller_spec.rb:16:in `block (3 levels) in <top (required)>'
Finished in 1.66 seconds
7 examples, 1 failure
Failed examples:
rspec ./spec/app/controllers/hello_world_controller_spec.rb:14 # The HelloWorld App per documentation does not have bogus content发布于 2013-01-15 01:41:26
原来罪魁祸首在Gemfile中同时有"bacon“和"rspec”。水豚被介绍到一个项目中,该项目利用bacon作为测试套件,正在尝试的示例是rspec。一旦培根从捆绑的宝石中移除,水豚规格就会按照文档运行。
由于bacon脚本或多或少在rspec下按原样运行,因此项目决策是删除bacon,并为测试套件使用rspec,并对bacon脚本进行较小的调整,以便在rspec下运行所有规范。
https://stackoverflow.com/questions/14305820
复制相似问题