-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3282eea
commit d3a7b7e
Showing
6 changed files
with
40 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,53 @@ | ||
require "spec_helper" | ||
|
||
describe FactoryGirl::AnonymousEvaluator do | ||
its(:attributes) { should == [] } | ||
end | ||
|
||
describe FactoryGirl::AnonymousEvaluator, "#set" do | ||
let(:attribute) { :one } | ||
let(:value) { lambda { @result ||= 0; @result += 1 } } | ||
|
||
def set_attribute | ||
subject.set(attribute, value) | ||
end | ||
|
||
shared_examples "#set on an AnonymousEvaluator" do | ||
it "adds the method to the evaluator" do | ||
set_attribute | ||
subject.set(attribute) | ||
subject.evaluator.new.one.should == 1 | ||
end | ||
|
||
it "tracks the attribute" do | ||
set_attribute | ||
subject.attributes.should == [attribute] | ||
end | ||
|
||
it "caches the result" do | ||
set_attribute | ||
subject.set(attribute) | ||
subject.evaluator.new.tap do |obj| | ||
obj.one.should == 1 | ||
obj.one.should == 1 | ||
end | ||
end | ||
|
||
it "evaluates the block in the context of the evaluator" do | ||
set_attribute | ||
subject.set(:two, lambda { one + 1 }) | ||
subject.set(attribute) | ||
second_attribute = stub("attribute", :name => :two, :to_proc => lambda { one + 1 }, :ignored => false) | ||
subject.set(second_attribute) | ||
subject.evaluator.new.two.should == 2 | ||
end | ||
end | ||
|
||
describe FactoryGirl::AnonymousEvaluator, "#set_ignored" do | ||
let(:attribute) { :one } | ||
let(:value) { lambda { @result ||= 0; @result += 1 } } | ||
describe FactoryGirl::AnonymousEvaluator do | ||
its(:attributes) { should == [] } | ||
end | ||
|
||
describe FactoryGirl::AnonymousEvaluator, "#set" do | ||
let(:value) { lambda { @result ||= 0; @result += 1 } } | ||
|
||
def set_attribute | ||
subject.set_ignored(attribute, value) | ||
end | ||
context "setting an ignored attribute" do | ||
let(:attribute) { stub("attribute", :name => :one, :to_proc => value, :ignored => true) } | ||
|
||
it "adds the method to the evaluator" do | ||
set_attribute | ||
subject.evaluator.new.one.should == 1 | ||
end | ||
it_behaves_like "#set on an AnonymousEvaluator" | ||
|
||
it "does not track the attribute" do | ||
set_attribute | ||
subject.attributes.should == [] | ||
it "does not track the attribute" do | ||
subject.set(attribute) | ||
subject.attributes.should be_empty | ||
end | ||
end | ||
|
||
it "caches the result" do | ||
set_attribute | ||
subject.evaluator.new.tap do |obj| | ||
obj.one.should == 1 | ||
obj.one.should == 1 | ||
context "setting an attribute" do | ||
let(:attribute) { stub("attribute", :name => :one, :to_proc => value, :ignored => false) } | ||
|
||
it_behaves_like "#set on an AnonymousEvaluator" | ||
|
||
it "tracks the attribute" do | ||
subject.set(attribute) | ||
subject.attributes.should == [:one] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters