Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Separated unit and acceptance tests to isolate Rails-related dependen…

…cies
  • Loading branch information...
commit f3366b69f2ae6d3409cdb5fef9aaa8363c167a47 1 parent fc8ce3a
@jferris jferris authored
Showing with 93 additions and 41 deletions.
  1. +17 −3 Rakefile
  2. +16 −0 spec/acceptance/acceptance_helper.rb
  3. +2 −1  spec/{integration_spec.rb → acceptance/acceptance_spec.rb}
  4. 0  spec/{ → acceptance}/models.rb
  5. +1 −1  spec/{factory_girl → acceptance}/syntax/blueprint_spec.rb
  6. +1 −1  spec/{factory_girl → acceptance}/syntax/generate_spec.rb
  7. +1 −1  spec/{factory_girl → acceptance}/syntax/make_spec.rb
  8. +1 −1  spec/{factory_girl → acceptance}/syntax/sham_spec.rb
  9. +1 −1  spec/factory_girl/aliases_spec.rb
  10. +1 −1  spec/factory_girl/attribute/association_spec.rb
  11. +1 −1  spec/factory_girl/attribute/callback_spec.rb
  12. +1 −1  spec/factory_girl/attribute/dynamic_spec.rb
  13. +1 −1  spec/factory_girl/attribute/static_spec.rb
  14. +1 −1  spec/factory_girl/attribute_spec.rb
  15. +11 −2 spec/factory_girl/factory_spec.rb
  16. +1 −1  spec/factory_girl/proxy/attributes_for_spec.rb
  17. +1 −1  spec/factory_girl/proxy/build_spec.rb
  18. +1 −1  spec/factory_girl/proxy/create_spec.rb
  19. +1 −1  spec/factory_girl/proxy/stub_spec.rb
  20. +1 −1  spec/factory_girl/proxy_spec.rb
  21. +1 −1  spec/factory_girl/sequence_spec.rb
  22. +31 −19 spec/spec_helper.rb
View
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']
View
16 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'
+
View
3  spec/integration_spec.rb → spec/acceptance/acceptance_spec.rb
@@ -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
View
0  spec/models.rb → spec/acceptance/models.rb
File renamed without changes
View
2  spec/factory_girl/syntax/blueprint_spec.rb → spec/acceptance/syntax/blueprint_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+require 'spec_helper'
require 'factory_girl/syntax/blueprint'
View
2  spec/factory_girl/syntax/generate_spec.rb → spec/acceptance/syntax/generate_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
+require 'spec_helper'
require 'factory_girl/syntax/generate'
View
2  spec/factory_girl/syntax/make_spec.rb → spec/acceptance/syntax/make_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+require 'spec_helper'
require 'factory_girl/syntax/make'
View
2  spec/factory_girl/syntax/sham_spec.rb → spec/acceptance/syntax/sham_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+require 'spec_helper'
require 'factory_girl/syntax/sham'
View
2  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
View
2  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
View
2  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
View
2  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
View
2  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
View
2  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
View
13 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
@@ -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
View
2  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
View
2  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
View
2  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
View
2  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
View
2  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
View
2  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
View
50 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
Please sign in to comment.
Something went wrong with that request. Please try again.