diff --git a/.gitignore b/.gitignore index a8829be..412aef9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ *.swp *.swo -.* *.gem coverage/* diff --git a/.rbenv-version b/.rbenv-version new file mode 100644 index 0000000..0a95b9f --- /dev/null +++ b/.rbenv-version @@ -0,0 +1 @@ +1.9.2-p290 diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..36c31a6 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--colour -f doc diff --git a/.rvmrc b/.rvmrc new file mode 100644 index 0000000..dd62a1a --- /dev/null +++ b/.rvmrc @@ -0,0 +1 @@ +rvm use 1.9.2@cranky --create diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6010a4f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ +# Overview of Changes + +## 0.3.0 + +* Factory.debug was broken on ActiveModel based classes, now works with them + +* Attributes can be skipped by setting the value to :skip. e.g. crank(:user, :name => :skip) will + generate a User instance without calling or assigning anything to the name attribute + +* Updated dev environment for latest rspec compatibility (2.6.0) + +## 0.2.0 + +Changes between version prior to this were not tracked here diff --git a/Gemfile b/Gemfile index 937e61f..b30125d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,11 +1,12 @@ source "http://gemcutter.org" group :development do + gem "rake" gem "gemcutter" end group :test do - gem "rspec", "1.3.0" + gem "rspec" gem "rcov" end diff --git a/Gemfile.lock b/Gemfile.lock index d404977..42370d3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,14 +1,24 @@ GEM remote: http://gemcutter.org/ specs: - gemcutter (0.6.1) - rcov (0.9.8) - rspec (1.3.0) + diff-lcs (1.1.2) + gemcutter (0.7.0) + rake (0.9.2) + rcov (0.9.9) + rspec (2.6.0) + rspec-core (~> 2.6.0) + rspec-expectations (~> 2.6.0) + rspec-mocks (~> 2.6.0) + rspec-core (2.6.4) + rspec-expectations (2.6.0) + diff-lcs (~> 1.1.2) + rspec-mocks (2.6.0) PLATFORMS ruby DEPENDENCIES gemcutter + rake rcov - rspec (= 1.3.0) + rspec diff --git a/lib/cranky/factory.rb b/lib/cranky/factory.rb index 87ee72a..f324272 100644 --- a/lib/cranky/factory.rb +++ b/lib/cranky/factory.rb @@ -39,7 +39,12 @@ def attributes_for(what, attrs={}) def debug(*args) item = build(*args) if !item.valid? - raise "Oops, the #{item.class} created by the Factory has the following errors: #{item.errors}" + if item.errors.respond_to?("messages") + errors = item.errors.messages + else + errors = item.errors + end + raise "Oops, the #{item.class} created by the Factory has the following errors: #{errors}" end item end diff --git a/lib/cranky/job.rb b/lib/cranky/job.rb index 80af64f..802f4ed 100644 --- a/lib/cranky/job.rb +++ b/lib/cranky/job.rb @@ -23,7 +23,9 @@ def execute item = get_constant(attributes[:class] ? attributes[:class] : @target).new # Assign all explicit attributes first attributes.each do |attribute, value| - item.send("#{attribute}=", value) if item.respond_to?("#{attribute}=") && !value.respond_to?("call") + unless value == :skip + item.send("#{attribute}=", value) if item.respond_to?("#{attribute}=") && !value.respond_to?("call") + end end # Then call any blocks attributes.each do |attribute, value| diff --git a/rakefile b/rakefile index bb7cc07..33c2124 100644 --- a/rakefile +++ b/rakefile @@ -2,12 +2,12 @@ $:.unshift File.expand_path("../lib", __FILE__) require 'cranky' require 'rubygems' -require 'spec/rake/spectask' +require 'rspec/core' +require 'rspec/core/rake_task' desc "Run specs" -Spec::Rake::SpecTask.new(:spec) do |t| - t.spec_files = Dir.glob("spec/**/*_spec.rb") - t.spec_opts = ["-c"] +RSpec::Core::RakeTask.new(:spec) do |t| + t.pattern = ("spec/**/*_spec.rb") t.rcov = true end diff --git a/spec/cranky_spec.rb b/spec/cranky_spec.rb index ba30605..088ab22 100644 --- a/spec/cranky_spec.rb +++ b/spec/cranky_spec.rb @@ -97,9 +97,9 @@ it "should allow blocks to be passed into the define method" do Factory.build(:user, :name => "jenny", :email => lambda{ |u| "#{u.name}@home.com" }).email.should == "jenny@home.com" - Factory.build(:user, :name => lambda{"jimmy" + " cranky"}).name.should == "jimmy cranky" + Factory.build(:user, :name => lambda { |u| "jimmy" + " cranky" }).name.should == "jimmy cranky" Factory.build(:user, :name => "jenny", :email => Proc.new{ |u| "#{u.name}@home.com" }).email.should == "jenny@home.com" - Factory.build(:user, :name => Proc.new{"jimmy" + " cranky"}).name.should == "jimmy cranky" + Factory.build(:user, :name => Proc.new{ |u| "jimmy" + " cranky" }).name.should == "jimmy cranky" end it "allows factories to call other factories" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b320d6a..16b32e6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,5 @@ require 'rubygems' -require 'spec' +require 'rspec' require 'cranky'