【发布时间】:2014-03-29 07:09:42
【问题描述】:
我正在使用 Rspec、Capybara 和 Selenium (WebDriver) 来测试我的 Rails 应用程序,这是一个简单的在线商店。这是失败的规范的简化版本:
describe 'Team Order' do
let(:product) { Product.last }
before do
create :product_with_color_and_size
end
it 'goes to product page', js: true do
visit add_team_order_path(product)
expect(page).to have_content(product.name)
end
end
具体来说,Selenium 驱动的 Firefox 窗口显示我的应用程序的 404 页面,导致检查产品名称失败。
当我从it 块内调用debugger 并查询Product.last 时,我可以在测试数据库中看到有问题的产品。所以我怀疑 Selenium 击中了我的应用程序的错误实例......或其他东西。
不确定这是否相关,但浏览器指向 http://127.0.0.1:49736/products/product-10/add-team-order(尽管端口在 rspec 运行之间发生变化)。
我的问题是,我能做些什么来验证它是否击中了正确的实例?如果不是,我可以采取哪些步骤来解决?
编辑:
spec_helper.rb 中的database_cleaner 配置:
RSpec.configure do |config|
config.before :suite do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with :truncation
end
config.before :each do
DatabaseCleaner.start
end
config.after :each do
DatabaseCleaner.clean
end
【问题讨论】:
标签: ruby-on-rails-3.2 selenium-webdriver