Ruby on rails 黄瓜+;水豚+;轨道不';t渲染模型
我有模型产品,我用Ruby on rails 黄瓜+;水豚+;轨道不';t渲染模型,ruby-on-rails,database,cucumber,capybara,Ruby On Rails,Database,Cucumber,Capybara,我有模型产品,我用渲染它。我有一个模板_product.html.erb,其中包含。当我在开发环境的浏览器中访问此页面时,它会显示我的产品 现在我在运行我的黄瓜,它看不到我的产品 我用FactoryGirl在“给定”中创建产品,如下所示: Given(/^(\d+) products are created$/) do |n| n.to_i.times do create(:product) end end Then I visit my
渲染它。我有一个模板_product.html.erb,其中包含
。当我在开发环境的浏览器中访问此页面时,它会显示我的产品
现在我在运行我的黄瓜,它看不到我的产品
我用FactoryGirl在“给定”中创建产品,如下所示:
Given(/^(\d+) products are created$/) do |n|
n.to_i.times do
create(:product)
end
end
Then I visit my page and in "then I check it like this"
Then(/^I should see paginated products$/) do
puts Product.all
puts page.body
products = Product.all
products[0..9].each do |product|
page.should have_selector "a", text: product.name
end
end
puts Product.all打印有效产品,但puts page.body打印我的页面而不打印呈现的产品
下面是我的env.rb文件:
require 'cucumber/rails'
World FactoryGirl::Syntax::Methods
ActionController::Base.allow_rescue = false
Cucumber::Rails::World.use_transactional_fixtures = true
Cucumber::Rails::Database.javascript_strategy = :truncation
为什么水豚不呈现我的模板
谢谢
更新:
虽然
放置Product.all
打印我的产品,但我视图中的
显示0用于测试。奇怪…您使用的是哪种水豚驱动程序?默认设置:我相信是rack\u测试,但是selenium对您的循环没有帮助,您可以尝试page。应该有\u链接(product.name)
问题是在运行测试期间,页面不包含此链接,但是,当我手动访问此页面时,我确实遇到了一个类似的问题,我花了一些时间来解决,问题是我没有访问我预期要进行测试的站点,所以请重新检查您是否确实访问了您想要测试的站点;)