一些奇怪的事情发生在水豚和rspec上,我在Ruby 1.9.3上设置Padrino 0.10.7,rspec 2.11.0,capybara 2.0.2。在rspec中,capybara匹配器总是将eval设置为TRUE。为什么?
一个基本的Padrino项目设置了haml和rspec(没有自定义代码,但!),而不仅仅是加载一个“/”页面(我确认它会按预期的方式渲染“puts page.content”下面)。这是简单的规格。 “虚假”不存在,但“家庭”确实......注意到,当我向控制台投放时,预期的真/假是正确的,但由于某种原因,匹配器没有正确地看到真假。
的一个线索,我到目前为止在于使用应have_content(“虚假”),该报告说,PROC预计第二规格...
./spec/controllers/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
end
spec_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
使用pry或调试器来检查您的应用程序在运行时! – phoet
我之前没有使用pry,它看起来像ruby-debug在1.9.3中被打破。我该怎么做才能使用pry,我在寻找什么? –
花费一些时间在这上面,看起来Rspec确实期待Proc而不是Matcher类(这是什么Capybara :: RSpecMatchers :: HaveText是)。 Rspec的API是否改变了? –