如何在运行场景之前让工厂模型保存到 MySQL?- Rails 2 & Cucumber



当我从控制台运行以下命令@county = FactoryGirl.create(:state)时,一个新的state行被添加到MySQL中,但是当我使用一个步骤文件调用相同的代码时,只有国家& &;区域行被添加,即没有状态行被添加,在数据库中没有状态导致我的大部分测试失败&我不明白为什么。

我使用Rails 2.3.2, cucumber 1.1.4, capybara 1.0.1 &硒

工厂。rb文件:

require 'factory_girl'
FactoryGirl.define do
     factory :country do |f|
       f.name 'USA'
       f.country_code 'US'
       f.currency_code 'USD'   
     end
    factory :region do |f|
      f.name 'East Coast'
      f.association :country   
    end
    factory :state do |f|
      f.name 'CA'
      f.association :region
      f.association :country   
    end     

结束

这里是.feature文件:

Feature: New User Registration
  Scenario: A user should be able to create an account 
    Given there is a state
    And I am on the new user registration page
    ...

和认证步骤文件:

Given /^there is a state$/ do
  @county = FactoryGirl.create(:state)
end

您的认证步骤显示您正在将:state对象分配给@country…这是原因吗,还是打错了?

最新更新