我正在使用带有 selenium-webdriver gem 的 Rspec 来测试 Web 应用程序。我想在我的测试中不包括工厂来模拟用户,而不是每次都手动创建一个用户。因此,我制作了 gem install factory_girl,在我的 spec_helper 中添加了 required 行,创建了一个工厂并在我的 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
Run Code Online (Sandbox Code Playgroud)
我的 factory.rb 文件:
FactoryGirl.define do
factory :user do
name "testuser"
password "freestyle"
inventory true
end
end
Run Code Online (Sandbox Code Playgroud)
我的 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 = …Run Code Online (Sandbox Code Playgroud)