p = Factory(:model)
ap Model.find(:all) #output to prove that it's getting created
so... the print shows that the IDs of the objects is going up.... but the database remains empty as I continually refresh the view on MySQL workbench -- so my cucumber tests fail, beca开发者_C百科use the controllers pull stuff from the database... but there is nothing in the database! =(
My Gem file: test
group :test do
gem "cucumber", "~>0.10.3"
gem "cucumber-rails", "0.3.2"
gem "launchy"
gem "hpricot"
gem "gherkin", "~>2.4.0"
gem "capybara", "0.4.1.2"
gem "rspec", "1.3.2"
gem "rspec-rails", "1.3.2"
gem "rspec-core"
gem "rspec-expectations"
gem "webrat", "0.7.0"
gem "database_cleaner"
gem "factory_girl", "1.2.4"
gem "shoulda", :require => nil
gem "shoulda-matchers", :git => "https://github.com/thoughtbot/shoulda-matchers"
gem "awesome_print"
gem "cobravsmongoose"
end
My Requires for env.rb (cucumber env)
ENV["RAILS_ENV"] = 'test'
ENV["RACK_ENV"] = 'test'
BASE_DOMAIN = "myapp.dev" #using POW
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
require 'cucumber/rails/world'
require 'cucumber/rails/active_record'
require 'cucumber/web/tableish'
require 'cucumber/rails/rspec'
require 'rake'
require 'shoulda'
require 'factory_girl'
require 'factory_girl/step_definitions'
require 'awesome_print'
require 'capybara/rails'
require 'capybara/cucumber'
require 'capybara/session'
And in envs/test.rb
Bundler.require(:test) #just in case I forgot something
EDIT:
Some console output Factory(:model).errors =>
#<ActiveRecord::Errors:0x10c5a6498 @base=#<ModelName id: 1, name: "Ready or not", status: 0, account_id: 2, user_id: 1, created_at: "2011-09-08 15:09:05", updated_at: "2011-09-08 15:09:05", description: "Things are not as they used to be", value: #<BigDecimal:10cb2c188,'0.12345E5',9(18)>, category_id: nil, allow_downloads: true, visibility: 1, locked: nil>, @errors=#<OrderedHash {}>>
And looking at the console during runtime, this object is def getting in INSERT INTO command... but there is this:
RELEASE SAVEPOINT active_record_1
SQL (1.3ms) ROLLBACK
which I feel might be what is causing the problem.... some sort of pre-emptive rollback.
Try this then:
in env.rb
require 'database_cleaner'
require 'database_cleaner/cucumber'
DatabaseCleaner.strategy = nil
in features/support/env.rb make sure that you have
# This will prevent the deletion of the data written in the test db until the end of the
# cucumber feature
Cucumber::Rails::World.use_transactional_fixtures = false
by default this is true so it looks like nothing goes in the db.
I would begin by seeing if there are any validation errors when the object is being saved, ie
p Factory(:model).errors
and then, if there are none, to start watching what active record does by adding a logger to stdout:
ActiveRecord::Base.logger = Logger.new(STDOUT)
and using that to make sure the data is being written to the db.
Past those things, I would try updating to the 2.1 version of FactoryGirl and seeing if that makes a difference.
In the file features/support/env.rb, you should set DatabaseCleaner.strategy = :truncation
精彩评论