我使用Rspec和硒-webdriver gem来测试一个web应用程序。我想在我的测试中排除工厂模拟用户,而不是每次手动创建用户。 所以,我做了gem安装factory_girl,在spec_helper中添加了需要的内容,创建了一个工厂并在我的spec文件中包含了一些行。并运行测试时,我得到一个错误 故障/错误:FactoryGirl.build(:用户) NameError: 未初始化的常数用户Rspec +工厂女孩(没有导轨!)
这里是我的spec_helper.rb
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
我factories.rb文件:
FactoryGirl.define do
factory :user do
name "testuser"
password "freestyle"
inventory true
end
end
而且我test_spec文件:
require "json"
require "selenium-webdriver"
require "rspec"
require "factory_girl"
FactoryGirl.find_definitions
include RSpec::Expectations
describe "MallSpec" do
before(:all) do
FactoryGirl.build(:user)
@driver = Selenium::WebDriver.for :firefox
@base_url = "http://localhost:9000/"
@accept_next_alert = true
@driver.manage.timeouts.implicit_wait = 30
@driver.manage.window.resize_to(1301, 744)
@verification_errors = []
end
我的spec_file位于项目的根目录中。我的factories.rb文件位于/ spec目录以及test_spec.rb本身。 任何人都可以帮助我解决这个问题或指出我做错了什么?
什么是“用户”在您的应用程序的情况下? – meagar 2015-02-23 19:53:16