【发布时间】:2015-06-14 22:33:12
【问题描述】:
我在非 RoR 项目中使用 Rspec 3.2 和 Capybara 2.4。我正在尝试使用 Capybara gem 提供的功能模式进行测试。
$ cat .rspec
--color
--require spec_helper
$ cat spec/features/test_spec.rb
feature 'login' do
username ="rspec#{Time.now.to_i}"
valid_email = "#{username}@gmail.com"
scenario 'with valid email' do
sign_up_with valid_email, 'pwd', 'pwd', username
expect(page).to have_content('LOGOUT')
end
end
$ cat spec/support/session_helper.rb
module SessionHelper
def sign_up_with(email, password, confirm_password, username)
visit '/signup'
fill_in 'email', with: email
fill_in 'password', with: password
fill_in 'passconf', with: confirm_password
fill_in 'username', with: username
click_button 'submit'
end
end
$ cat spec/spec_helper.rb
require 'capybara/rspec'
Capybara.default_driver = :selenium
RSpec.configure do |config|
...
config.include SessionHelper, type: :feature
...
end
这是一个非 RoR 项目,当我运行测试时出现此错误:
$ rspec
spec/spec_helper.rb:26:in `block in <top (required)>': uninitialized constant SessionHelper (NameError)
在线文档中有很多示例,我按照示例构建了我的文件,但它不起作用。
【问题讨论】:
标签: ruby testing rspec capybara bdd