Use rspec2

This commit is contained in:
Joe Ferris 2010-11-11 15:33:45 -06:00
parent 6b0b3ce748
commit 3b5f90f981
13 changed files with 129 additions and 76 deletions

View File

@ -1,7 +1,7 @@
source "http://rubygems.org"
gem "cucumber"
gem "rake"
gem "rspec", "~> 1.3"
gem "rspec", "~> 2.0"
gem "rcov"
gem "activerecord", :require => false
gem "rr"

View File

@ -32,7 +32,14 @@ GEM
rake (0.8.7)
rcov (0.9.9)
rr (1.0.2)
rspec (1.3.0)
rspec (2.1.0)
rspec-core (~> 2.1.0)
rspec-expectations (~> 2.1.0)
rspec-mocks (~> 2.1.0)
rspec-core (2.1.0)
rspec-expectations (2.1.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.1.0)
sqlite3-ruby (1.3.2)
term-ansicolor (1.0.5)
tzinfo (0.3.23)
@ -47,5 +54,5 @@ DEPENDENCIES
rake
rcov
rr
rspec (~> 1.3)
rspec (~> 2.0)
sqlite3-ruby

View File

@ -5,7 +5,7 @@ require 'rake/rdoctask'
require 'rcov/rcovtask'
require 'date'
require 'rake/gempackagetask'
require 'spec/rake/spectask'
require 'rspec/core/rake_task'
require 'cucumber/rake/task'
require 'appraisal'
@ -16,15 +16,13 @@ end
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']
RSpec::Core::RakeTask.new('unit') do |t|
t.pattern = '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']
RSpec::Core::RakeTask.new('acceptance') do |t|
t.pattern = 'spec/acceptance/**/*_spec.rb'
end
end

View File

@ -5,7 +5,7 @@ gem "rr"
gem "activerecord", "~> 2.1"
gem "rake"
gem "sqlite3-ruby", {:require=>false}
gem "rspec", "~> 1.3"
gem "rspec", "~> 2.0"
gem "rcov"
gem "cucumber"
gem "appraisal"

View File

@ -22,7 +22,14 @@ GEM
rake (0.8.7)
rcov (0.9.9)
rr (1.0.2)
rspec (1.3.0)
rspec (2.1.0)
rspec-core (~> 2.1.0)
rspec-expectations (~> 2.1.0)
rspec-mocks (~> 2.1.0)
rspec-core (2.1.0)
rspec-expectations (2.1.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.1.0)
sqlite3-ruby (1.3.2)
term-ansicolor (1.0.5)
@ -36,5 +43,5 @@ DEPENDENCIES
rake
rcov
rr
rspec (~> 1.3)
rspec (~> 2.0)
sqlite3-ruby

View File

@ -5,7 +5,7 @@ gem "rr"
gem "activerecord", "~> 2.3"
gem "rake"
gem "sqlite3-ruby", {:require=>false}
gem "rspec", "~> 1.3"
gem "rspec", "~> 2.0"
gem "rcov"
gem "cucumber"
gem "appraisal"

View File

@ -22,7 +22,14 @@ GEM
rake (0.8.7)
rcov (0.9.9)
rr (1.0.2)
rspec (1.3.0)
rspec (2.1.0)
rspec-core (~> 2.1.0)
rspec-expectations (~> 2.1.0)
rspec-mocks (~> 2.1.0)
rspec-core (2.1.0)
rspec-expectations (2.1.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.1.0)
sqlite3-ruby (1.3.2)
term-ansicolor (1.0.5)
@ -36,5 +43,5 @@ DEPENDENCIES
rake
rcov
rr
rspec (~> 1.3)
rspec (~> 2.0)
sqlite3-ruby

View File

@ -5,7 +5,7 @@ gem "rr"
gem "activerecord", "~> 3.0"
gem "rake"
gem "sqlite3-ruby", {:require=>false}
gem "rspec", "~> 1.3"
gem "rspec", "~> 2.0"
gem "rcov"
gem "cucumber"
gem "appraisal"

View File

@ -32,7 +32,14 @@ GEM
rake (0.8.7)
rcov (0.9.9)
rr (1.0.2)
rspec (1.3.0)
rspec (2.1.0)
rspec-core (~> 2.1.0)
rspec-expectations (~> 2.1.0)
rspec-mocks (~> 2.1.0)
rspec-core (2.1.0)
rspec-expectations (2.1.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.1.0)
sqlite3-ruby (1.3.2)
term-ansicolor (1.0.5)
tzinfo (0.3.23)
@ -47,5 +54,5 @@ DEPENDENCIES
rake
rcov
rr
rspec (~> 1.3)
rspec (~> 2.0)
sqlite3-ruby

View File

@ -24,7 +24,7 @@ describe FactoryGirl::Factory do
before do
@name = :user
@class = define_constant('User')
@class = define_class('User')
@factory = FactoryGirl::Factory.new(@name)
end
@ -265,7 +265,7 @@ describe FactoryGirl::Factory, "with a name ending in s" do
include DefinesConstants
before do
define_constant('Business')
define_class('Business')
@name = :business
@class = Business
@factory = FactoryGirl::Factory.new(@name)
@ -321,8 +321,8 @@ describe FactoryGirl::Factory, "for namespaced class" do
include DefinesConstants
before do
define_constant('Admin')
define_constant('Admin::Settings')
define_class('Admin')
define_class('Admin::Settings')
@name = :settings
@class = Admin::Settings
@ -343,8 +343,8 @@ describe FactoryGirl::Factory do
include DefinesConstants
before do
define_constant('User')
define_constant('Admin', User)
define_class('User')
define_class('Admin', User)
end
it "should raise an ArgumentError when trying to use a non-existent strategy" do

View File

@ -8,6 +8,22 @@ share_examples_for "finds definitions" do
subject { FactoryGirl }
end
RSpec::Matchers.define :require_definitions_from do |file|
match do |given|
@has_received = have_received.method_missing(:require, file)
@has_received.matches?(given)
end
description do
"require definitions from #{file}"
end
failure_message_for_should do
@has_received.failure_message
end
end
describe "definition loading" do
def self.in_directory_with_files(*files)
before do
@ -28,41 +44,35 @@ describe "definition loading" do
end
end
def require_definitions_from(file)
simple_matcher do |given, matcher|
has_received = have_received.method_missing(:require, file)
result = has_received.matches?(given)
matcher.description = "require definitions from #{file}"
matcher.failure_message = has_received.failure_message
result
end
end
describe "with factories.rb" do
in_directory_with_files 'factories.rb'
it_should_behave_like "finds definitions"
it { should require_definitions_from('factories.rb') }
it_should_behave_like "finds definitions" do
it { should require_definitions_from('factories.rb') }
end
end
%w(spec test).each do |dir|
describe "with a factories file under #{dir}" do
in_directory_with_files File.join(dir, 'factories.rb')
it_should_behave_like "finds definitions"
it { should require_definitions_from("#{dir}/factories.rb") }
it_should_behave_like "finds definitions" do
it { should require_definitions_from("#{dir}/factories.rb") }
end
end
describe "with a factories file under #{dir}/factories" do
in_directory_with_files File.join(dir, 'factories', 'post_factory.rb')
it_should_behave_like "finds definitions"
it { should require_definitions_from("#{dir}/factories/post_factory.rb") }
it_should_behave_like "finds definitions" do
it { should require_definitions_from("#{dir}/factories/post_factory.rb") }
end
end
describe "with several factories files under #{dir}/factories" do
in_directory_with_files File.join(dir, 'factories', 'post_factory.rb'),
File.join(dir, 'factories', 'person_factory.rb')
it_should_behave_like "finds definitions"
it { should require_definitions_from("#{dir}/factories/post_factory.rb") }
it { should require_definitions_from("#{dir}/factories/person_factory.rb") }
it_should_behave_like "finds definitions" do
it { should require_definitions_from("#{dir}/factories/post_factory.rb") }
it { should require_definitions_from("#{dir}/factories/person_factory.rb") }
end
end
describe "with several factories files under #{dir}/factories in non-alphabetical order" do
@ -80,10 +90,11 @@ describe "definition loading" do
in_directory_with_files File.join(dir, 'factories.rb'),
File.join(dir, 'factories', 'post_factory.rb'),
File.join(dir, 'factories', 'person_factory.rb')
it_should_behave_like "finds definitions"
it { should require_definitions_from("#{dir}/factories.rb") }
it { should require_definitions_from("#{dir}/factories/post_factory.rb") }
it { should require_definitions_from("#{dir}/factories/person_factory.rb") }
it_should_behave_like "finds definitions" do
it { should require_definitions_from("#{dir}/factories.rb") }
it { should require_definitions_from("#{dir}/factories/post_factory.rb") }
it { should require_definitions_from("#{dir}/factories/person_factory.rb") }
end
end
end
end

View File

@ -2,45 +2,61 @@ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
$LOAD_PATH << File.join(File.dirname(__FILE__))
require 'rubygems'
require 'spec'
require 'spec/autorun'
require 'rspec'
require 'rspec/autorun'
require 'rr'
require 'factory_girl'
Spec::Runner.configure do |config|
config.mock_with RR::Adapters::Rspec
module RR
module Adapters
module Rspec
def self.included(mod)
RSpec.configuration.backtrace_clean_patterns.push(RR::Errors::BACKTRACE_IDENTIFIER)
end
end
end
end
RSpec.configure do |config|
config.mock_framework = :rr
RSpec::Core::ExampleGroup.send(:include, RR::Adapters::Rspec)
config.after do
FactoryGirl.factories.clear
FactoryGirl.sequences.clear
end
end
share_as :DefinesConstants do
before do
@defined_constants = []
end
module DefinesConstants
def self.included(example_group)
example_group.class_eval 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)
after do
@defined_constants.reverse.each do |path|
namespace, class_name = *constant_path(path)
namespace.send(:remove_const, class_name)
end
end
def define_class(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
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