mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Separated unit and acceptance tests to isolate Rails-related dependencies
This commit is contained in:
parent
fc8ce3ab7e
commit
f3366b69f2
22 changed files with 93 additions and 41 deletions
20
Rakefile
20
Rakefile
|
@ -9,15 +9,29 @@ require 'cucumber/rake/task'
|
|||
|
||||
desc 'Default: run the specs and features.'
|
||||
task :default do
|
||||
system("rake -s spec:unit;")
|
||||
%w(2.1 2.3 3.0).each do |version|
|
||||
system("RAILS_VERSION=#{version} rake -s spec features;")
|
||||
system("RAILS_VERSION=#{version} rake -s spec:acceptance features;")
|
||||
end
|
||||
end
|
||||
|
||||
Spec::Rake::SpecTask.new do |t|
|
||||
t.spec_opts = ['--options', "spec/spec.opts"]
|
||||
namespace :spec do
|
||||
desc "Run unit specs"
|
||||
Spec::Rake::SpecTask.new('unit') do |t|
|
||||
t.spec_opts = ['--options', "spec/spec.opts"]
|
||||
t.spec_files = FileList['spec/factory_girl/**/*_spec.rb']
|
||||
end
|
||||
|
||||
desc "Run acceptance specs"
|
||||
Spec::Rake::SpecTask.new('acceptance') do |t|
|
||||
t.spec_opts = ['--options', "spec/spec.opts"]
|
||||
t.spec_files = FileList['spec/acceptance/**/*_spec.rb']
|
||||
end
|
||||
end
|
||||
|
||||
desc "Run the unit and acceptance specs"
|
||||
task :spec => ['spec:unit', 'spec:acceptance']
|
||||
|
||||
desc 'Performs code coverage on the factory_girl plugin.'
|
||||
Rcov::RcovTask.new do |t|
|
||||
t.test_files = FileList['spec/*_spec.rb']
|
||||
|
|
16
spec/acceptance/acceptance_helper.rb
Normal file
16
spec/acceptance/acceptance_helper.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
case ENV['RAILS_VERSION']
|
||||
when '2.1' then
|
||||
gem 'activerecord', '~>2.1.0'
|
||||
when '3.0' then
|
||||
gem 'activerecord', '~>3.0.0'
|
||||
else
|
||||
gem 'activerecord', '~>2.3.0'
|
||||
end
|
||||
|
||||
require 'active_record'
|
||||
require 'active_record/version'
|
||||
|
||||
puts "Running specs using Rails #{ActiveRecord::VERSION::STRING}"
|
||||
|
||||
require 'acceptance/models'
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
require 'acceptance/acceptance_helper'
|
||||
|
||||
describe "integration" do
|
||||
before do
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
||||
require 'spec_helper'
|
||||
|
||||
require 'factory_girl/syntax/blueprint'
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
require 'factory_girl/syntax/generate'
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
||||
require 'spec_helper'
|
||||
|
||||
require 'factory_girl/syntax/make'
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
||||
require 'spec_helper'
|
||||
|
||||
require 'factory_girl/syntax/sham'
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
describe Factory, "aliases" do
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
describe Factory::Attribute::Association do
|
||||
before do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
describe Factory::Attribute::Callback do
|
||||
before do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
describe Factory::Attribute::Dynamic do
|
||||
before do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
describe Factory::Attribute::Static do
|
||||
before do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
describe Factory::Attribute do
|
||||
before do
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
describe Factory do
|
||||
include DefinesConstants
|
||||
|
||||
before do
|
||||
define_constant('User')
|
||||
define_constant('Admin', User)
|
||||
define_constant('Business')
|
||||
define_constant('Admin::Settings')
|
||||
end
|
||||
|
||||
describe "defining a factory" do
|
||||
before do
|
||||
@name = :user
|
||||
|
@ -411,7 +420,7 @@ describe Factory do
|
|||
end
|
||||
|
||||
it "should build Admin::Settings class from Admin::Settings string" do
|
||||
factory = Factory.define(@name.to_s, :class => @class.name.underscore) {}
|
||||
factory = Factory.define(@name.to_s, :class => 'admin/settings') {}
|
||||
factory.build_class.should == @class
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
describe Factory::Proxy::AttributesFor do
|
||||
before do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
describe Factory::Proxy::Build do
|
||||
before do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
describe Factory::Proxy::Create do
|
||||
before do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
describe Factory::Proxy::Stub do
|
||||
before do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
describe Factory::Proxy do
|
||||
before do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
describe Factory::Sequence do
|
||||
describe "a sequence" do
|
||||
|
|
|
@ -1,30 +1,42 @@
|
|||
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
||||
$: << File.join(File.dirname(__FILE__))
|
||||
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
||||
$LOAD_PATH << File.join(File.dirname(__FILE__))
|
||||
|
||||
require 'rubygems'
|
||||
|
||||
case ENV['RAILS_VERSION']
|
||||
when '2.1' then
|
||||
gem 'activerecord', '~>2.1.0'
|
||||
when '3.0' then
|
||||
gem 'activerecord', '~>3.0.0'
|
||||
else
|
||||
gem 'activerecord', '~>2.3.0'
|
||||
end
|
||||
|
||||
require 'active_record'
|
||||
require 'active_record/version'
|
||||
|
||||
puts "Running specs using Rails #{ActiveRecord::VERSION::STRING}"
|
||||
|
||||
require 'spec'
|
||||
require 'spec/autorun'
|
||||
require 'rr'
|
||||
|
||||
require 'models'
|
||||
|
||||
require 'factory_girl'
|
||||
|
||||
Spec::Runner.configure do |config|
|
||||
config.mock_with RR::Adapters::Rspec
|
||||
end
|
||||
|
||||
share_as :DefinesConstants do
|
||||
before do
|
||||
@defined_constants = []
|
||||
end
|
||||
|
||||
after do
|
||||
@defined_constants.reverse.each do |path|
|
||||
namespace, class_name = *constant_path(path)
|
||||
namespace.send(:remove_const, class_name)
|
||||
end
|
||||
end
|
||||
|
||||
def define_constant(path, base = Object, &block)
|
||||
namespace, class_name = *constant_path(path)
|
||||
klass = Class.new(base)
|
||||
namespace.const_set(class_name, klass)
|
||||
klass.class_eval(&block) if block_given?
|
||||
@defined_constants << path
|
||||
klass
|
||||
end
|
||||
|
||||
def constant_path(constant_name)
|
||||
names = constant_name.split('::')
|
||||
class_name = names.pop
|
||||
namespace = names.inject(Object) { |result, name| result.const_get(name) }
|
||||
[namespace, class_name]
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue