我正在使用selenium-webdriver gem和Rspec来测试一个Web应用程序。我希望在我的测试中包含工厂,以模拟用户并避免每次手动创建用户。
因此,我安装了factory_girl gem,并在我的spec_helper文件中添加了必要的代码行,创建了一个工厂,并在我的spec文件中包含了一些代码。但是,在运行测试时,我收到了以下错误信息: Failure/Error: FactoryGirl.build(:user) NameError: uninitialized constant User 这是我的spec_helper.rb文件:
因此,我安装了factory_girl gem,并在我的spec_helper文件中添加了必要的代码行,创建了一个工厂,并在我的spec文件中包含了一些代码。但是,在运行测试时,我收到了以下错误信息: Failure/Error: FactoryGirl.build(:user) NameError: uninitialized constant User 这是我的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
我的测试规范文件:
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文件以及test_spec.rb文件都在/spec目录中。 有人能帮我解决这个问题或指出我做错了什么吗?