Skip to content

Commit

Permalink
Fixed/improved Factory.debug test
Browse files Browse the repository at this point in the history
  • Loading branch information
ginty committed Aug 10, 2016
1 parent a0ab810 commit cdc9629
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
source "http://gemcutter.org"

group :development do
gem "activemodel"
gem "rake"
gem "gemcutter"
end
Expand Down
18 changes: 17 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
GEM
remote: http://gemcutter.org/
specs:
activemodel (4.2.6)
activesupport (= 4.2.6)
builder (~> 3.1)
activesupport (4.2.6)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
builder (3.2.2)
diff-lcs (1.1.2)
docile (1.1.5)
gemcutter (0.7.0)
i18n (0.7.0)
json (1.8.3)
minitest (5.9.0)
rake (0.9.2)
rspec (2.6.0)
rspec-core (~> 2.6.0)
Expand All @@ -19,15 +31,19 @@ GEM
json (~> 1.8)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
thread_safe (0.3.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)

PLATFORMS
ruby

DEPENDENCIES
activemodel
gemcutter
rake
rspec
simplecov

BUNDLED WITH
1.12.2
1.12.5
18 changes: 7 additions & 11 deletions spec/cranky_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,15 @@
describe "debugger" do

it "raises an error if the factory produces an invalid object when enabled (rails only)" do
error = false
begin
Factory.debug(:user, :valid => false)
rescue
error = true
end
error.should == true
expect { Factory.debug(:user) }.to raise_error(
'Oops, the User created by the Factory has the following errors: {:required_attr=>["can\'t be blank"]}'
)
end

it "debug works like build and create when there are no errors" do
Factory.debug(:user).class.should == User
Factory.debug(:user).saved?.should == false
Factory.debug!(:user).saved?.should == true
Factory.debug(:user, required_attr: true).class.should == User
Factory.debug(:user, required_attr: true).saved?.should == false
Factory.debug!(:user, required_attr: true).saved?.should == true
end

end
Expand Down Expand Up @@ -151,7 +147,7 @@
end

it "returns nothing extra in the attributes" do
crank(:user_attrs).size.should == 6
crank(:user_attrs).size.should == 5
end

specify "attributes for works with factory methods using inherit" do
Expand Down
22 changes: 8 additions & 14 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
SimpleCov.start

require 'cranky'
require 'active_model'

RSpec.configure do |config|
config.expect_with(:rspec) { |c| c.syntax = :should }
end

class TestClass
attr_accessor :valid
include ActiveModel::Validations

attr_accessor :required_attr

validates_presence_of :required_attr

def save
@saved = true
Expand All @@ -18,14 +23,6 @@ def saved?
!!@saved
end

def valid?
@valid
end

def errors
"some validation errors"
end

def attributes
self.instance_variables
end
Expand Down Expand Up @@ -59,7 +56,6 @@ def user_manually
u.unique = "value#{n}"
u.email = "[email protected]"
u.address = Factory.build(:address)
u.valid = true
u
end

Expand All @@ -69,8 +65,7 @@ def user_by_define
:role => :user,
:unique => "value#{n}",
:email => "[email protected]",
:address => Factory.create(:address),
:valid => true
:address => Factory.create(:address)
u.argument_received = true if options[:argument_supplied]
u
end
Expand All @@ -86,8 +81,7 @@ def admin_by_define

def address
define :address => "25 Wisteria Lane",
:city => "New York",
:valid => true
:city => "New York"
end

def user_hash
Expand Down

0 comments on commit cdc9629

Please sign in to comment.