Skip to content

Commit

Permalink
Separated unit and acceptance tests to isolate Rails-related dependen…
Browse files Browse the repository at this point in the history
…cies
  • Loading branch information
jferris committed Jun 10, 2010
1 parent fc8ce3a commit f3366b6
Show file tree
Hide file tree
Showing 22 changed files with 93 additions and 41 deletions.
20 changes: 17 additions & 3 deletions Rakefile
Expand Up @@ -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']
Expand Down
16 changes: 16 additions & 0 deletions spec/acceptance/acceptance_helper.rb
@@ -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
Expand Down
File renamed without changes.
@@ -1,4 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'spec_helper'

require 'factory_girl/syntax/blueprint'

Expand Down
@@ -1,4 +1,4 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
require 'spec_helper'

require 'factory_girl/syntax/generate'

Expand Down
@@ -1,4 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'spec_helper'

require 'factory_girl/syntax/make'

Expand Down
@@ -1,4 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'spec_helper'

require 'factory_girl/syntax/sham'

Expand Down
2 changes: 1 addition & 1 deletion spec/factory_girl/aliases_spec.rb
@@ -1,4 +1,4 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require 'spec_helper'

describe Factory, "aliases" do

Expand Down
2 changes: 1 addition & 1 deletion spec/factory_girl/attribute/association_spec.rb
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/factory_girl/attribute/callback_spec.rb
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/factory_girl/attribute/dynamic_spec.rb
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/factory_girl/attribute/static_spec.rb
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/factory_girl/attribute_spec.rb
@@ -1,4 +1,4 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require 'spec_helper'

describe Factory::Attribute do
before do
Expand Down
13 changes: 11 additions & 2 deletions spec/factory_girl/factory_spec.rb
@@ -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
Expand Down Expand Up @@ -411,7 +420,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion spec/factory_girl/proxy/attributes_for_spec.rb
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/factory_girl/proxy/build_spec.rb
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/factory_girl/proxy/create_spec.rb
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/factory_girl/proxy/stub_spec.rb
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/factory_girl/proxy_spec.rb
@@ -1,4 +1,4 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require 'spec_helper'

describe Factory::Proxy do
before do
Expand Down
2 changes: 1 addition & 1 deletion spec/factory_girl/sequence_spec.rb
@@ -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
Expand Down
50 changes: 31 additions & 19 deletions spec/spec_helper.rb
@@ -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

0 comments on commit f3366b6

Please sign in to comment.