Permalink
Browse files

spec_helper include fix for Ruby 1.9.2 compatibility.

New rspec "subject" API.
  • Loading branch information...
1 parent 2b6e9de commit 44e75e33914f910e0bcd877a6897b36444f24565 @jaymcgavren committed Jul 15, 2011
@@ -1,20 +1,20 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require "rubyonacid/factories/attraction"
require "shared_factory_specs"
include RubyOnAcid
describe AttractionFactory do
- before :each do
- @it = AttractionFactory.new
+ subject do
+ AttractionFactory.new
end
describe "general behavior" do
before :each do
- @it.source_factories << mock('Factory', :get_unit => 0.2)
- @it.attractor_factory = mock('Factory', :get_unit => 0.3)
+ subject.source_factories << mock('Factory', :get_unit => 0.2)
+ subject.attractor_factory = mock('Factory', :get_unit => 0.3)
end
it_should_behave_like "a factory"
@@ -24,46 +24,46 @@
describe "#get_unit" do
it "retrieves values from source factory and attracts them toward values from the attractor factory" do
- @it.source_factories << mock('Factory', :get_unit => 0.0)
- @it.attractor_factory = mock('Factory', :get_unit => 1.0)
- @it.get_unit(:x).should > 0.0
- @it.attractor_factory = mock('Factory', :get_unit => 0.9)
- @it.get_unit(:x).should > 0.0
- @it.attractor_factory = mock('Factory', :get_unit => 0.5)
- @it.get_unit(:x).should > 0.0
- @it.attractor_factory = mock('Factory', :get_unit => 0.1)
- @it.get_unit(:x).should > 0.0
- @it.attractor_factory = mock('Factory', :get_unit => 0.1)
- @it.get_unit(:x).should > 0.0
+ subject.source_factories << mock('Factory', :get_unit => 0.0)
+ subject.attractor_factory = mock('Factory', :get_unit => 1.0)
+ subject.get_unit(:x).should > 0.0
+ subject.attractor_factory = mock('Factory', :get_unit => 0.9)
+ subject.get_unit(:x).should > 0.0
+ subject.attractor_factory = mock('Factory', :get_unit => 0.5)
+ subject.get_unit(:x).should > 0.0
+ subject.attractor_factory = mock('Factory', :get_unit => 0.1)
+ subject.get_unit(:x).should > 0.0
+ subject.attractor_factory = mock('Factory', :get_unit => 0.1)
+ subject.get_unit(:x).should > 0.0
end
it "exerts greater attraction if values are closer" do
pending
- @it.source_factories << mock('Factory', :get_unit => 0.0)
- @it.attractor_factory = mock('Factory')
- @it.attractor_factory.should_receive(:get_unit).and_return(1.0)
- distant_value = @it.get_unit(:x)
- @it.attractor_factory.should_receive(:get_unit).and_return(0.9)
- close_value = @it.get_unit(:x)
+ subject.source_factories << mock('Factory', :get_unit => 0.0)
+ subject.attractor_factory = mock('Factory')
+ subject.attractor_factory.should_receive(:get_unit).and_return(1.0)
+ distant_value = subject.get_unit(:x)
+ subject.attractor_factory.should_receive(:get_unit).and_return(0.9)
+ close_value = subject.get_unit(:x)
close_value.should > distant_value
distant_value = close_value
- @it.attractor_factory.should_receive(:get_unit).and_return(0.8)
- close_value = @it.get_unit(:x)
+ subject.attractor_factory.should_receive(:get_unit).and_return(0.8)
+ close_value = subject.get_unit(:x)
close_value.should > distant_value
distant_value = close_value
- @it.attractor_factory.should_receive(:get_unit).and_return(0.2)
- close_value = @it.get_unit(:x)
+ subject.attractor_factory.should_receive(:get_unit).and_return(0.2)
+ close_value = subject.get_unit(:x)
close_value.should > distant_value
distant_value = close_value
- @it.attractor_factory.should_receive(:get_unit).and_return(0.0)
- close_value = @it.get_unit(:x)
+ subject.attractor_factory.should_receive(:get_unit).and_return(0.0)
+ close_value = subject.get_unit(:x)
close_value.should > distant_value
end
it "reduces source value if attractor's value is lower" do
- @it.source_factories << mock('Factory', :get_unit => 0.9)
- @it.attractor_factory = mock('Factory', :get_unit => 0.1)
- @it.get_unit(:x).should < 0.9
+ subject.source_factories << mock('Factory', :get_unit => 0.9)
+ subject.attractor_factory = mock('Factory', :get_unit => 0.1)
+ subject.get_unit(:x).should < 0.9
end
end
@@ -1,20 +1,20 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require "rubyonacid/factories/combination"
require "shared_factory_specs"
include RubyOnAcid
describe CombinationFactory do
- before :each do
- @it = CombinationFactory.new
+ subject do
+ CombinationFactory.new
end
describe "general behavior" do
before :each do
- @it.source_factories << mock('Factory', :get_unit => 0.2)
- @it.source_factories << mock('Factory', :get_unit => 0.3)
+ subject.source_factories << mock('Factory', :get_unit => 0.2)
+ subject.source_factories << mock('Factory', :get_unit => 0.3)
end
it_should_behave_like "a factory"
@@ -24,115 +24,115 @@
describe "#get_unit" do
it "retrieves values from source factories and adds them together" do
- @it.source_factories << mock('Factory', :get_unit => 0.2)
- @it.source_factories << mock('Factory', :get_unit => 0.3)
- @it.get_unit(:x).should be_within(MARGIN).of(0.5)
- @it.source_factories << mock('Factory', :get_unit => 0.1)
- @it.get_unit(:x).should be_within(MARGIN).of(0.6)
+ subject.source_factories << mock('Factory', :get_unit => 0.2)
+ subject.source_factories << mock('Factory', :get_unit => 0.3)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.5)
+ subject.source_factories << mock('Factory', :get_unit => 0.1)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.6)
end
it "can constrain sum to 0.0 through 1.0" do
- @it.constrain_mode = CombinationFactory::CONSTRAIN
- @it.source_factories << mock('Factory', :get_unit => 0.2)
- @it.source_factories << mock('Factory', :get_unit => 0.3)
- @it.source_factories << mock('Factory', :get_unit => 0.7)
- @it.get_unit(:x).should be_within(MARGIN).of(1.0)
+ subject.constrain_mode = CombinationFactory::CONSTRAIN
+ subject.source_factories << mock('Factory', :get_unit => 0.2)
+ subject.source_factories << mock('Factory', :get_unit => 0.3)
+ subject.source_factories << mock('Factory', :get_unit => 0.7)
+ subject.get_unit(:x).should be_within(MARGIN).of(1.0)
end
it "uses wrap mode by default" do
- @it.source_factories << mock('Factory', :get_unit => 0.4)
- @it.source_factories << mock('Factory', :get_unit => 0.7)
- @it.get_unit(:x).should be_within(MARGIN).of(0.1)
+ subject.source_factories << mock('Factory', :get_unit => 0.4)
+ subject.source_factories << mock('Factory', :get_unit => 0.7)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.1)
end
it "can wrap > 1.0 value around" do
- @it.constrain_mode = CombinationFactory::WRAP
- @it.source_factories << mock('Factory', :get_unit => 0.2)
- @it.source_factories << mock('Factory', :get_unit => 0.3)
- @it.source_factories << mock('Factory', :get_unit => 0.7)
- @it.get_unit(:x).should be_within(MARGIN).of(0.2)
+ subject.constrain_mode = CombinationFactory::WRAP
+ subject.source_factories << mock('Factory', :get_unit => 0.2)
+ subject.source_factories << mock('Factory', :get_unit => 0.3)
+ subject.source_factories << mock('Factory', :get_unit => 0.7)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.2)
end
it "can make value 'rebound' off boundary" do
- @it.constrain_mode = CombinationFactory::REBOUND
- @it.source_factories = [
+ subject.constrain_mode = CombinationFactory::REBOUND
+ subject.source_factories = [
mock('Factory', :get_unit => 0.4),
mock('Factory', :get_unit => 0.7)
]
- @it.get_unit(:x).should be_within(MARGIN).of(0.9)
- @it.source_factories = [
+ subject.get_unit(:x).should be_within(MARGIN).of(0.9)
+ subject.source_factories = [
mock('Factory', :get_unit => 1.0),
mock('Factory', :get_unit => 1.0),
mock('Factory', :get_unit => 0.1)
]
- @it.get_unit(:x).should be_within(MARGIN).of(0.1)
- @it.source_factories = [
+ subject.get_unit(:x).should be_within(MARGIN).of(0.1)
+ subject.source_factories = [
mock('Factory', :get_unit => 0.1),
mock('Factory', :get_unit => 0.1)
]
- @it.get_unit(:x).should be_within(MARGIN).of(0.2)
- @it.operation = CombinationFactory::SUBTRACT
- @it.source_factories = [
+ subject.get_unit(:x).should be_within(MARGIN).of(0.2)
+ subject.operation = CombinationFactory::SUBTRACT
+ subject.source_factories = [
mock('Factory', :get_unit => 0.1),
mock('Factory', :get_unit => 0.4)
]
- @it.get_unit(:x).should be_within(MARGIN).of(0.3)
- @it.source_factories = [
+ subject.get_unit(:x).should be_within(MARGIN).of(0.3)
+ subject.source_factories = [
mock('Factory', :get_unit => 0.1),
mock('Factory', :get_unit => 0.5),
mock('Factory', :get_unit => 0.5)
]
- @it.get_unit(:x).should be_within(MARGIN).of(0.9)
- @it.source_factories = [
+ subject.get_unit(:x).should be_within(MARGIN).of(0.9)
+ subject.source_factories = [
mock('Factory', :get_unit => 0.1),
mock('Factory', :get_unit => 1.0),
mock('Factory', :get_unit => 1.0)
]
- @it.get_unit(:x).should be_within(MARGIN).of(0.1)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.1)
end
end
describe "subtraction" do
it "can subtract values from source factories" do
- @it.operation = CombinationFactory::SUBTRACT
- @it.source_factories << mock('Factory', :get_unit => 0.7)
- @it.source_factories << mock('Factory', :get_unit => 0.3)
- @it.get_unit(:x).should be_within(MARGIN).of(0.4)
- @it.source_factories << mock('Factory', :get_unit => 0.1)
- @it.get_unit(:x).should be_within(MARGIN).of(0.3)
+ subject.operation = CombinationFactory::SUBTRACT
+ subject.source_factories << mock('Factory', :get_unit => 0.7)
+ subject.source_factories << mock('Factory', :get_unit => 0.3)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.4)
+ subject.source_factories << mock('Factory', :get_unit => 0.1)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.3)
end
it "can wrap < 0.0 value around" do
- @it.operation = CombinationFactory::SUBTRACT
- @it.constrain_mode = CombinationFactory::WRAP
- @it.source_factories << mock('Factory', :get_unit => 0.5)
- @it.source_factories << mock('Factory', :get_unit => 0.7)
- @it.get_unit(:x).should be_within(MARGIN).of(0.8)
+ subject.operation = CombinationFactory::SUBTRACT
+ subject.constrain_mode = CombinationFactory::WRAP
+ subject.source_factories << mock('Factory', :get_unit => 0.5)
+ subject.source_factories << mock('Factory', :get_unit => 0.7)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.8)
end
end
describe "multiplication" do
it "can get product of values from source factories" do
- @it.operation = CombinationFactory::MULTIPLY
- @it.source_factories << mock('Factory', :get_unit => 0.7)
- @it.source_factories << mock('Factory', :get_unit => 0.5)
- @it.get_unit(:x).should be_within(MARGIN).of(0.35)
- @it.source_factories << mock('Factory', :get_unit => 0.1)
- @it.get_unit(:x).should be_within(MARGIN).of(0.035)
+ subject.operation = CombinationFactory::MULTIPLY
+ subject.source_factories << mock('Factory', :get_unit => 0.7)
+ subject.source_factories << mock('Factory', :get_unit => 0.5)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.35)
+ subject.source_factories << mock('Factory', :get_unit => 0.1)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.035)
end
end
describe "division" do
it "can divide values from source factories" do
- @it.operation = CombinationFactory::DIVIDE
- @it.source_factories << mock('Factory', :get_unit => 0.1)
- @it.source_factories << mock('Factory', :get_unit => 0.2)
- @it.get_unit(:x).should be_within(MARGIN).of(0.5) #0.1 / 0.2 = 0.5
- @it.source_factories << mock('Factory', :get_unit => 0.9)
- @it.get_unit(:x).should be_within(MARGIN).of(0.555) #0.5 / 0.9 = 0.5555...
+ subject.operation = CombinationFactory::DIVIDE
+ subject.source_factories << mock('Factory', :get_unit => 0.1)
+ subject.source_factories << mock('Factory', :get_unit => 0.2)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.5) #0.1 / 0.2 = 0.5
+ subject.source_factories << mock('Factory', :get_unit => 0.9)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.555) #0.5 / 0.9 = 0.5555...
end
end
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require "shared_factory_specs"
require 'rubyonacid/factories/constant'
@@ -7,17 +7,17 @@
describe ConstantFactory do
- before :each do
- @it = ConstantFactory.new
+ subject do
+ ConstantFactory.new
end
it_should_behave_like "a factory"
it "always returns the same value" do
- @it.value = 0.1
- @it.get_unit(:x).should == 0.1
- @it.get_unit(:x).should == 0.1
+ subject.value = 0.1
+ subject.get_unit(:x).should == 0.1
+ subject.get_unit(:x).should == 0.1
end
end
Oops, something went wrong. Retry.

0 comments on commit 44e75e3

Please sign in to comment.