Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

spec_helper include fix for Ruby 1.9.2 compatibility.

New rspec "subject" API.
  • Loading branch information...
commit 44e75e33914f910e0bcd877a6897b36444f24565 1 parent 2b6e9de
@jaymcgavren authored
View
62 spec/factories/attraction_spec.rb
@@ -1,4 +1,4 @@
-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"
@@ -6,15 +6,15 @@
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
View
120 spec/factories/combination_spec.rb
@@ -1,4 +1,4 @@
-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"
@@ -6,15 +6,15 @@
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,71 +24,71 @@
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
@@ -96,43 +96,43 @@
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
View
12 spec/factories/constant_spec.rb
@@ -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
View
56 spec/factories/flash_spec.rb
@@ -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/flash'
@@ -6,44 +6,44 @@
describe FlashFactory do
- before :each do
- @it = FlashFactory.new
+ subject do
+ FlashFactory.new
end
it_should_behave_like "a factory"
it "returns 1.0 three times, then 0.0 three times, then loops" do
- @it.get_unit(:x).should == 1.0
- @it.get_unit(:x).should == 1.0
- @it.get_unit(:x).should == 1.0
- @it.get_unit(:x).should == 0.0
- @it.get_unit(:x).should == 0.0
- @it.get_unit(:x).should == 0.0
- @it.get_unit(:x).should == 1.0
- @it.get_unit(:x).should == 1.0
- @it.get_unit(:x).should == 1.0
- @it.get_unit(:x).should == 0.0
- @it.get_unit(:x).should == 0.0
- @it.get_unit(:x).should == 0.0
+ subject.get_unit(:x).should == 1.0
+ subject.get_unit(:x).should == 1.0
+ subject.get_unit(:x).should == 1.0
+ subject.get_unit(:x).should == 0.0
+ subject.get_unit(:x).should == 0.0
+ subject.get_unit(:x).should == 0.0
+ subject.get_unit(:x).should == 1.0
+ subject.get_unit(:x).should == 1.0
+ subject.get_unit(:x).should == 1.0
+ subject.get_unit(:x).should == 0.0
+ subject.get_unit(:x).should == 0.0
+ subject.get_unit(:x).should == 0.0
end
it "can take a different interval" do
- @it.interval = 2
- @it.get_unit(:x).should == 1.0
- @it.get_unit(:x).should == 1.0
- @it.get_unit(:x).should == 0.0
- @it.get_unit(:x).should == 0.0
- @it.get_unit(:x).should == 1.0
+ subject.interval = 2
+ subject.get_unit(:x).should == 1.0
+ subject.get_unit(:x).should == 1.0
+ subject.get_unit(:x).should == 0.0
+ subject.get_unit(:x).should == 0.0
+ subject.get_unit(:x).should == 1.0
end
it "handles multiple keys" do
- @it.interval = 2
- @it.get_unit(:x).should == 1.0
- @it.get_unit(:y).should == 1.0
- @it.get_unit(:x).should == 1.0
- @it.get_unit(:y).should == 1.0
- @it.get_unit(:x).should == 0.0
- @it.get_unit(:y).should == 0.0
+ subject.interval = 2
+ subject.get_unit(:x).should == 1.0
+ subject.get_unit(:y).should == 1.0
+ subject.get_unit(:x).should == 1.0
+ subject.get_unit(:y).should == 1.0
+ subject.get_unit(:x).should == 0.0
+ subject.get_unit(:y).should == 0.0
end
end
View
40 spec/factories/increment_spec.rb
@@ -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/increment'
@@ -7,36 +7,36 @@
describe IncrementFactory do
- before :each do
- @it = IncrementFactory.new
+ subject do
+ IncrementFactory.new
end
it_should_behave_like "a factory"
it "Stops at 1 if increment is positive" do
- @it.interval = 0.3
- @it.get_unit(:x).should be_within(MARGIN).of(0.3)
- @it.get_unit(:x).should be_within(MARGIN).of(0.6)
- @it.get_unit(:x).should be_within(MARGIN).of(0.9)
- @it.get_unit(:x).should be_within(MARGIN).of(1.0)
- @it.get_unit(:x).should be_within(MARGIN).of(1.0)
+ subject.interval = 0.3
+ subject.get_unit(:x).should be_within(MARGIN).of(0.3)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.6)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.9)
+ subject.get_unit(:x).should be_within(MARGIN).of(1.0)
+ subject.get_unit(:x).should be_within(MARGIN).of(1.0)
end
it "Stops at 0 if increment is negative" do
- @it.interval = -0.3
- @it.get_unit(:x).should be_within(MARGIN).of(0.7)
- @it.get_unit(:x).should be_within(MARGIN).of(0.4)
- @it.get_unit(:x).should be_within(MARGIN).of(0.1)
- @it.get_unit(:x).should be_within(MARGIN).of(0.0)
- @it.get_unit(:x).should be_within(MARGIN).of(0.0)
+ subject.interval = -0.3
+ subject.get_unit(:x).should be_within(MARGIN).of(0.7)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.4)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.1)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.0)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.0)
end
it "handles multiple keys" do
- @it.interval = 0.3
- @it.get_unit(:x).should be_within(MARGIN).of(0.3)
- @it.get_unit(:y).should be_within(MARGIN).of(0.3)
- @it.get_unit(:x).should be_within(MARGIN).of(0.6)
- @it.get_unit(:y).should be_within(MARGIN).of(0.6)
+ subject.interval = 0.3
+ subject.get_unit(:x).should be_within(MARGIN).of(0.3)
+ subject.get_unit(:y).should be_within(MARGIN).of(0.3)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.6)
+ subject.get_unit(:y).should be_within(MARGIN).of(0.6)
end
end
View
94 spec/factories/input_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require "rubyonacid/factories/input"
require "shared_factory_specs"
@@ -6,14 +6,14 @@
describe InputFactory do
- before :each do
- @it = InputFactory.new
+ subject do
+ InputFactory.new
end
describe "general behavior" do
before :each do
- @it.source_factories << mock('Factory', :get_unit => 0.2)
+ subject.source_factories << mock('Factory', :get_unit => 0.2)
end
it_should_behave_like "a factory"
@@ -23,29 +23,29 @@
describe "#get_unit" do
it "retrieves values assigned to a key" do
- @it.put(:x, 0.1)
- @it.get(:x).should == 0.1
+ subject.put(:x, 0.1)
+ subject.get(:x).should == 0.1
end
it "stores only latest input value" do
- @it.put(:x, 0.1)
- @it.put(:x, 0.2)
- @it.get(:x).should == 0.2
+ subject.put(:x, 0.1)
+ subject.put(:x, 0.2)
+ subject.get(:x).should == 0.2
end
it "maps to a different key if the requested one isn't present" do
- @it.put(:x, 0.1)
- @it.get(:y).should == 0.1
+ subject.put(:x, 0.1)
+ subject.get(:y).should == 0.1
end
it "returns 0 if a key has no values" do
- @it.get(:z).should == 0.0
+ subject.get(:z).should == 0.0
end
it "returns 0 only after mapping a different key" do
- @it.put(:x, 0.2)
- @it.get(:y).should == 0.2
- @it.get(:z).should == 0.0
+ subject.put(:x, 0.2)
+ subject.get(:y).should == 0.2
+ subject.get(:z).should == 0.0
end
end
@@ -53,41 +53,41 @@
describe "scaling" do
it "scales highest seen values for a key to 0 to 1 range" do
- @it.put(:x, 0.0)
- @it.get(:x).should be_within(MARGIN).of(0.0)
- @it.put(:x, 1.0)
- @it.get(:x).should be_within(MARGIN).of(1.0)
- @it.put(:x, 2.0)
- @it.get(:x).should be_within(MARGIN).of(1.0)
- @it.put(:x, 1.0)
- @it.get(:x).should be_within(MARGIN).of(0.5)
- @it.put(:x, 0.0)
- @it.get(:x).should be_within(MARGIN).of(0.0)
- @it.put(:x, 4.0)
- @it.get(:x).should be_within(MARGIN).of(1.0)
- @it.put(:x, 3.0)
- @it.get(:x).should be_within(MARGIN).of(0.75)
- @it.put(:x, 0.0)
- @it.get(:x).should be_within(MARGIN).of(0.0)
+ subject.put(:x, 0.0)
+ subject.get(:x).should be_within(MARGIN).of(0.0)
+ subject.put(:x, 1.0)
+ subject.get(:x).should be_within(MARGIN).of(1.0)
+ subject.put(:x, 2.0)
+ subject.get(:x).should be_within(MARGIN).of(1.0)
+ subject.put(:x, 1.0)
+ subject.get(:x).should be_within(MARGIN).of(0.5)
+ subject.put(:x, 0.0)
+ subject.get(:x).should be_within(MARGIN).of(0.0)
+ subject.put(:x, 4.0)
+ subject.get(:x).should be_within(MARGIN).of(1.0)
+ subject.put(:x, 3.0)
+ subject.get(:x).should be_within(MARGIN).of(0.75)
+ subject.put(:x, 0.0)
+ subject.get(:x).should be_within(MARGIN).of(0.0)
end
it "scales lowest seen values for a key to 0 to 1 range" do
- @it.put(:x, 0.0)
- @it.get(:x).should be_within(MARGIN).of(0.0)
- @it.put(:x, 1.0)
- @it.get(:x).should be_within(MARGIN).of(1.0)
- @it.put(:x, -2.0)
- @it.get(:x).should be_within(MARGIN).of(0.0)
- @it.put(:x, 1.0)
- @it.get(:x).should be_within(MARGIN).of(1.0)
- @it.put(:x, 0.0)
- @it.get(:x).should be_within(MARGIN).of(0.666)
- @it.put(:x, -2.0)
- @it.get(:x).should be_within(MARGIN).of(0.0)
- @it.put(:x, 2.0)
- @it.get(:x).should be_within(MARGIN).of(1.0)
- @it.put(:x, 1.0)
- @it.get(:x).should be_within(MARGIN).of(0.75)
+ subject.put(:x, 0.0)
+ subject.get(:x).should be_within(MARGIN).of(0.0)
+ subject.put(:x, 1.0)
+ subject.get(:x).should be_within(MARGIN).of(1.0)
+ subject.put(:x, -2.0)
+ subject.get(:x).should be_within(MARGIN).of(0.0)
+ subject.put(:x, 1.0)
+ subject.get(:x).should be_within(MARGIN).of(1.0)
+ subject.put(:x, 0.0)
+ subject.get(:x).should be_within(MARGIN).of(0.666)
+ subject.put(:x, -2.0)
+ subject.get(:x).should be_within(MARGIN).of(0.0)
+ subject.put(:x, 2.0)
+ subject.get(:x).should be_within(MARGIN).of(1.0)
+ subject.put(:x, 1.0)
+ subject.get(:x).should be_within(MARGIN).of(0.75)
end
end
View
32 spec/factories/lissajous_spec.rb
@@ -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/lissajous'
@@ -7,14 +7,14 @@
describe LissajousFactory do
- before :each do
- @it = LissajousFactory.new
+ subject do
+ LissajousFactory.new
end
describe "general behavior" do
before :each do
- @it.source_factories << mock('Factory', :get_unit => 0.2)
+ subject.source_factories << mock('Factory', :get_unit => 0.2)
end
it_should_behave_like "a factory"
@@ -24,21 +24,21 @@
describe "#get_unit" do
it "Returns x/y coordinates" do
- @it.interval = 0.5
- @it.get_unit(:x).should be_within(MARGIN).of(0.739)
- @it.get_unit(:y).should be_within(MARGIN).of(0.990)
- @it.get_unit(:x).should be_within(MARGIN).of(0.921)
- @it.get_unit(:y).should be_within(MARGIN).of(0.990)
- @it.get_unit(:x).should be_within(MARGIN).of(0.998)
- @it.get_unit(:y).should be_within(MARGIN).of(0.978)
+ subject.interval = 0.5
+ subject.get_unit(:x).should be_within(MARGIN).of(0.739)
+ subject.get_unit(:y).should be_within(MARGIN).of(0.990)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.921)
+ subject.get_unit(:y).should be_within(MARGIN).of(0.990)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.998)
+ subject.get_unit(:y).should be_within(MARGIN).of(0.978)
end
it "returns x for the first assigned key, y for the second, x again for the third, etc." do
- @it.interval = 0.5
- @it.get_unit(:x).should be_within(MARGIN).of(0.739)
- @it.get_unit(:y).should be_within(MARGIN).of(0.997)
- @it.get_unit(:z).should be_within(MARGIN).of(0.739)
- @it.get_unit(:x).should be_within(MARGIN).of(0.921)
+ subject.interval = 0.5
+ subject.get_unit(:x).should be_within(MARGIN).of(0.739)
+ subject.get_unit(:y).should be_within(MARGIN).of(0.997)
+ subject.get_unit(:z).should be_within(MARGIN).of(0.739)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.921)
end
end
View
40 spec/factories/loop_spec.rb
@@ -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/loop'
@@ -7,36 +7,36 @@
describe LoopFactory do
- before :each do
- @it = LoopFactory.new
+ subject do
+ LoopFactory.new
end
it_should_behave_like "a factory"
it "Loops to 0 if increment is positive" do
- @it.interval = 0.3
- @it.get_unit(:x).should be_within(MARGIN).of(0.3)
- @it.get_unit(:x).should be_within(MARGIN).of(0.6)
- @it.get_unit(:x).should be_within(MARGIN).of(0.9)
- @it.get_unit(:x).should be_within(MARGIN).of(0.2)
- @it.get_unit(:x).should be_within(MARGIN).of(0.5)
+ subject.interval = 0.3
+ subject.get_unit(:x).should be_within(MARGIN).of(0.3)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.6)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.9)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.2)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.5)
end
it "Loops to 1 if increment is negative" do
- @it.interval = -0.3
- @it.get_unit(:x).should be_within(MARGIN).of(0.7)
- @it.get_unit(:x).should be_within(MARGIN).of(0.4)
- @it.get_unit(:x).should be_within(MARGIN).of(0.1)
- @it.get_unit(:x).should be_within(MARGIN).of(0.8)
- @it.get_unit(:x).should be_within(MARGIN).of(0.5)
+ subject.interval = -0.3
+ subject.get_unit(:x).should be_within(MARGIN).of(0.7)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.4)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.1)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.8)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.5)
end
it "handles multiple keys" do
- @it.interval = 0.3
- @it.get_unit(:x).should be_within(MARGIN).of(0.3)
- @it.get_unit(:y).should be_within(MARGIN).of(0.3)
- @it.get_unit(:x).should be_within(MARGIN).of(0.6)
- @it.get_unit(:y).should be_within(MARGIN).of(0.6)
+ subject.interval = 0.3
+ subject.get_unit(:x).should be_within(MARGIN).of(0.3)
+ subject.get_unit(:y).should be_within(MARGIN).of(0.3)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.6)
+ subject.get_unit(:y).should be_within(MARGIN).of(0.6)
end
end
View
16 spec/factories/meta_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require 'rubyonacid/factories/meta'
require "shared_factory_specs"
@@ -6,16 +6,16 @@
describe MetaFactory do
- before :each do
- @it = MetaFactory.new
+ subject do
+ MetaFactory.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.1)
+ subject.source_factories << mock('Factory', :get_unit => 0.2)
+ subject.source_factories << mock('Factory', :get_unit => 0.1)
end
it_should_behave_like "a factory"
@@ -24,10 +24,10 @@
it "takes a list of factories, then randomly and permanently assigns a factory to each requested key" do
- @it.source_factories << mock('FactoryZero', :get_unit => 0.0)
- @it.source_factories << mock('FactoryOne', :get_unit => 1.0)
+ subject.source_factories << mock('FactoryZero', :get_unit => 0.0)
+ subject.source_factories << mock('FactoryOne', :get_unit => 1.0)
('a'..'z').each do |key|
- @it.get_unit(key.to_sym).should == @it.get_unit(key.to_sym)
+ subject.get_unit(key.to_sym).should == subject.get_unit(key.to_sym)
end
end
View
28 spec/factories/proximity_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require 'rubyonacid/factories/proximity'
require "shared_factory_specs"
@@ -6,14 +6,14 @@
describe ProximityFactory do
- before :each do
- @it = ProximityFactory.new
+ subject do
+ ProximityFactory.new
end
describe "general behavior" do
before :each do
- @it.source_factories << mock('Factory', :get_unit => 0.2)
+ subject.source_factories << mock('Factory', :get_unit => 0.2)
end
it_should_behave_like "a factory"
@@ -23,29 +23,29 @@
describe "#get_unit" do
it "requests value from the source factory and scales it based on its proximity to the target value" do
source_factory = mock('Factory')
- @it.source_factories << source_factory
- @it.target = 0.5
+ subject.source_factories << source_factory
+ subject.target = 0.5
source_factory.should_receive(:get_unit).with(:x).and_return(0.5)
- near_value = @it.get_unit(:x)
+ near_value = subject.get_unit(:x)
source_factory.should_receive(:get_unit).with(:x).and_return(0.7)
- far_value = @it.get_unit(:x)
+ far_value = subject.get_unit(:x)
near_value.should > far_value
end
it "should return 1.0 if source value matches target exactly" do
source_factory = mock('Factory')
- @it.source_factories << source_factory
- @it.target = 0.5
+ subject.source_factories << source_factory
+ subject.target = 0.5
source_factory.should_receive(:get_unit).with(:x).and_return(0.5)
- @it.get_unit(:x).should be_within(MARGIN).of(1.0)
+ subject.get_unit(:x).should be_within(MARGIN).of(1.0)
end
it "should approach zero as distance approaches 1.0" do
source_factory = mock('Factory')
- @it.source_factories << source_factory
- @it.target = 1.0
+ subject.source_factories << source_factory
+ subject.target = 1.0
source_factory.should_receive(:get_unit).with(:x).and_return(0.0)
- @it.get_unit(:x).should be_within(MARGIN).of(0.0)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.0)
end
end
View
100 spec/factories/queue_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require "rubyonacid/factories/queue"
require "shared_factory_specs"
@@ -6,14 +6,14 @@
describe QueueFactory do
- before :each do
- @it = QueueFactory.new
+ subject do
+ QueueFactory.new
end
describe "general behavior" do
before :each do
- @it.source_factories << mock('Factory', :get_unit => 0.2)
+ subject.source_factories << mock('Factory', :get_unit => 0.2)
end
it_should_behave_like "a factory"
@@ -23,29 +23,29 @@
describe "#get_unit" do
it "retrieves values assigned to a key" do
- @it.put(:x, 0.1)
- @it.get(:x).should == 0.1
+ subject.put(:x, 0.1)
+ subject.get(:x).should == 0.1
end
it "retrieves multiple queue values in order" do
- @it.put(:x, 0.1)
- @it.put(:x, 0.2)
- @it.get(:x).should == 0.1
- @it.get(:x).should == 0.2
+ subject.put(:x, 0.1)
+ subject.put(:x, 0.2)
+ subject.get(:x).should == 0.1
+ subject.get(:x).should == 0.2
end
it "maps to a different key if the requested one isn't present" do
- @it.put(:x, 0.1)
- @it.get(:y).should == 0.1
+ subject.put(:x, 0.1)
+ subject.get(:y).should == 0.1
end
it "returns 0 if a key is assigned but has no values" do
- @it.put(:x, 0.1)
- @it.put(:x, 0.2)
- @it.get(:y).should == 0.1
- @it.get(:y).should == 0.2
- @it.put(:z, 0.3)
- @it.get(:y).should == 0.0
+ subject.put(:x, 0.1)
+ subject.put(:x, 0.2)
+ subject.get(:y).should == 0.1
+ subject.get(:y).should == 0.2
+ subject.put(:z, 0.3)
+ subject.get(:y).should == 0.0
end
end
@@ -53,41 +53,41 @@
describe "scaling" do
it "scales highest seen values for a key to 0 to 1 range" do
- @it.put(:x, 0.0)
- @it.put(:x, 1.0)
- @it.get(:x).should be_within(MARGIN).of(0.0)
- @it.get(:x).should be_within(MARGIN).of(1.0)
- @it.put(:x, 0.0)
- @it.put(:x, 1.0)
- @it.put(:x, 2.0)
- @it.get(:x).should be_within(MARGIN).of(0.0)
- @it.get(:x).should be_within(MARGIN).of(0.5)
- @it.get(:x).should be_within(MARGIN).of(1.0)
- @it.put(:x, 0.0)
- @it.put(:x, 3.0)
- @it.put(:x, 4.0)
- @it.get(:x).should be_within(MARGIN).of(0.0)
- @it.get(:x).should be_within(MARGIN).of(0.75)
- @it.get(:x).should be_within(MARGIN).of(1.0)
+ subject.put(:x, 0.0)
+ subject.put(:x, 1.0)
+ subject.get(:x).should be_within(MARGIN).of(0.0)
+ subject.get(:x).should be_within(MARGIN).of(1.0)
+ subject.put(:x, 0.0)
+ subject.put(:x, 1.0)
+ subject.put(:x, 2.0)
+ subject.get(:x).should be_within(MARGIN).of(0.0)
+ subject.get(:x).should be_within(MARGIN).of(0.5)
+ subject.get(:x).should be_within(MARGIN).of(1.0)
+ subject.put(:x, 0.0)
+ subject.put(:x, 3.0)
+ subject.put(:x, 4.0)
+ subject.get(:x).should be_within(MARGIN).of(0.0)
+ subject.get(:x).should be_within(MARGIN).of(0.75)
+ subject.get(:x).should be_within(MARGIN).of(1.0)
end
it "scales lowest seen values for a key to 0 to 1 range" do
- @it.put(:x, 0.0)
- @it.put(:x, 1.0)
- @it.get(:x).should be_within(MARGIN).of(0.0)
- @it.get(:x).should be_within(MARGIN).of(1.0)
- @it.put(:x, 0.0)
- @it.put(:x, 1.0)
- @it.put(:x, -2.0)
- @it.get(:x).should be_within(MARGIN).of(0.666)
- @it.get(:x).should be_within(MARGIN).of(1.0)
- @it.get(:x).should be_within(MARGIN).of(0.0)
- @it.put(:x, -2.0)
- @it.put(:x, 2.0)
- @it.put(:x, 1.0)
- @it.get(:x).should be_within(MARGIN).of(0.0)
- @it.get(:x).should be_within(MARGIN).of(1.0)
- @it.get(:x).should be_within(MARGIN).of(0.75)
+ subject.put(:x, 0.0)
+ subject.put(:x, 1.0)
+ subject.get(:x).should be_within(MARGIN).of(0.0)
+ subject.get(:x).should be_within(MARGIN).of(1.0)
+ subject.put(:x, 0.0)
+ subject.put(:x, 1.0)
+ subject.put(:x, -2.0)
+ subject.get(:x).should be_within(MARGIN).of(0.666)
+ subject.get(:x).should be_within(MARGIN).of(1.0)
+ subject.get(:x).should be_within(MARGIN).of(0.0)
+ subject.put(:x, -2.0)
+ subject.put(:x, 2.0)
+ subject.put(:x, 1.0)
+ subject.get(:x).should be_within(MARGIN).of(0.0)
+ subject.get(:x).should be_within(MARGIN).of(1.0)
+ subject.get(:x).should be_within(MARGIN).of(0.75)
end
end
View
10 spec/factories/random_spec.rb
@@ -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/random"
@@ -6,15 +6,15 @@
describe RandomFactory do
- before :each do
- @it = RandomFactory.new
+ subject do
+ RandomFactory.new
end
it_should_behave_like "a factory"
it "generates random numbers between 0 and 1" do
- @it.get_unit(:x).should_not == @it.get_unit(:x)
- @it.get_unit(:x).should_not == @it.get_unit(:x)
+ subject.get_unit(:x).should_not == subject.get_unit(:x)
+ subject.get_unit(:x).should_not == subject.get_unit(:x)
end
end
View
16 spec/factories/random_walk_spec.rb
@@ -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/random_walk'
@@ -7,20 +7,20 @@
describe RandomWalkFactory do
- before :each do
- @it = RandomWalkFactory.new
+ subject do
+ RandomWalkFactory.new
end
it_should_behave_like "a factory"
it "increases or decreases prior key value by random amount within given interval" do
values = []
- values << @it.get_unit(:x)
- @it.interval = 0.3
- values << @it.get_unit(:x)
+ values << subject.get_unit(:x)
+ subject.interval = 0.3
+ values << subject.get_unit(:x)
values[1].should be_within(0.3).of(values[0])
- @it.interval = 0.01
- values << @it.get_unit(:x)
+ subject.interval = 0.01
+ values << subject.get_unit(:x)
values[2].should be_within(0.01).of(values[1])
end
View
38 spec/factories/repeat_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require 'rubyonacid/factories/repeat'
require "shared_factory_specs"
@@ -9,40 +9,40 @@
describe "general behavior" do
before :each do
- @it.source_factories << mock('Factory', :get_unit => 0.2)
+ subject.source_factories << mock('Factory', :get_unit => 0.2)
end
it_should_behave_like "a factory"
end
- before :each do
- @it = RepeatFactory.new
+ subject do
+ RepeatFactory.new
end
it "Requests a value from the source factory and repeats it a given number of times" do
source_factory = mock('Factory')
source_factory.should_receive(:get_unit).exactly(3).times.and_return(0.0, 1.0, 0.5)
- @it.source_factories << source_factory
- @it.repeat_count = 2
- @it.get_unit(:x).should == 0.0
- @it.get_unit(:x).should == 0.0
- @it.get_unit(:x).should == 1.0
- @it.get_unit(:x).should == 1.0
- @it.get_unit(:x).should == 0.5
+ subject.source_factories << source_factory
+ subject.repeat_count = 2
+ subject.get_unit(:x).should == 0.0
+ subject.get_unit(:x).should == 0.0
+ subject.get_unit(:x).should == 1.0
+ subject.get_unit(:x).should == 1.0
+ subject.get_unit(:x).should == 0.5
end
it "Tracks repeats on a per-key basis" do
source_factory = mock('Factory')
source_factory.should_receive(:get_unit).exactly(4).times.and_return(0.0, 1.0, 0.5, 0.75)
- @it.source_factories << source_factory
- @it.repeat_count = 2
- @it.get_unit(:x).should == 0.0
- @it.get_unit(:y).should == 1.0
- @it.get_unit(:x).should == 0.0
- @it.get_unit(:y).should == 1.0
- @it.get_unit(:x).should == 0.5
- @it.get_unit(:y).should == 0.75
+ subject.source_factories << source_factory
+ subject.repeat_count = 2
+ subject.get_unit(:x).should == 0.0
+ subject.get_unit(:y).should == 1.0
+ subject.get_unit(:x).should == 0.0
+ subject.get_unit(:y).should == 1.0
+ subject.get_unit(:x).should == 0.5
+ subject.get_unit(:y).should == 0.75
end
end
View
25 spec/factories/rinda_spec.rb
@@ -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/rinda'
@@ -11,16 +11,17 @@
describe RindaFactory do
- before :each do
- @it = RindaFactory.new
- @it.uri = "druby://127.0.0.1:7632"
- @space = Rinda::TupleSpaceProxy.new(DRbObject.new(nil, @it.uri))
+ subject do
+ factory = RindaFactory.new
+ factory.uri = "druby://127.0.0.1:7632"
+ @space = Rinda::TupleSpaceProxy.new(DRbObject.new(nil, factory.uri))
+ factory
end
describe "general behavior" do
before :each do
- @it.start_service
+ subject.start_service
end
it_should_behave_like "a factory"
@@ -28,19 +29,19 @@
end
it "gets keys from Rinda server" do
- @it.start_service
+ subject.start_service
@space.write([:x, 0.5])
- @it.get_unit(:x).should == 0.5
+ subject.get_unit(:x).should == 0.5
@space.write([:y, 0.6])
- @it.get_unit(:y).should == 0.6
+ subject.get_unit(:y).should == 0.6
end
it "gets keys from a backup factory when it cannot retrieve values via Rinda" do
- @it.start_service
+ subject.start_service
default_factory = mock('Factory')
default_factory.stub!(:get_unit).and_return(0.74)
- @it.source_factories << default_factory
- @it.get_unit(:a).should == 0.74
+ subject.source_factories << default_factory
+ subject.get_unit(:a).should == 0.74
end
end
View
48 spec/factories/rounding_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require 'rubyonacid/factories/rounding'
require "shared_factory_specs"
@@ -6,14 +6,14 @@
describe RoundingFactory do
- before :each do
- @it = RoundingFactory.new
+ subject do
+ RoundingFactory.new
end
describe "general behavior" do
before :each do
- @it.source_factories << mock('Factory', :get_unit => 0.2)
+ subject.source_factories << mock('Factory', :get_unit => 0.2)
end
it_should_behave_like "a factory"
@@ -22,48 +22,48 @@
it "Requests a value from the source factory and rounds it to a multiple of the requested number" do
source_factory = mock('Factory')
- @it.source_factories << source_factory
- @it.nearest = 0.3
+ subject.source_factories << source_factory
+ subject.nearest = 0.3
source_factory.should_receive(:get_unit).and_return(0.7)
- @it.get_unit(:x).should be_within(MARGIN).of(0.6)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.6)
source_factory.should_receive(:get_unit).and_return(0.8)
- @it.get_unit(:x).should be_within(MARGIN).of(0.9)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.9)
source_factory.should_receive(:get_unit).and_return(0.9)
- @it.get_unit(:x).should be_within(MARGIN).of(0.9)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.9)
source_factory.should_receive(:get_unit).and_return(1.0)
- @it.get_unit(:x).should be_within(MARGIN).of(0.9)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.9)
end
it "can round to multiples of 0.2" do
source_factory = mock('Factory')
- @it.source_factories << source_factory
- @it.nearest = 0.2
+ subject.source_factories << source_factory
+ subject.nearest = 0.2
source_factory.should_receive(:get_unit).and_return(0.0)
- @it.get_unit(:x).should be_within(MARGIN).of(0.0)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.0)
source_factory.should_receive(:get_unit).and_return(0.11)
- @it.get_unit(:x).should be_within(MARGIN).of(0.2)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.2)
source_factory.should_receive(:get_unit).and_return(0.2)
- @it.get_unit(:x).should be_within(MARGIN).of(0.2)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.2)
source_factory.should_receive(:get_unit).and_return(0.31)
- @it.get_unit(:x).should be_within(MARGIN).of(0.4)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.4)
source_factory.should_receive(:get_unit).and_return(0.4)
- @it.get_unit(:x).should be_within(MARGIN).of(0.4)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.4)
end
it "can round to multiples of 1.0" do
source_factory = mock('Factory')
- @it.source_factories << source_factory
- @it.nearest = 1.0
+ subject.source_factories << source_factory
+ subject.nearest = 1.0
source_factory.should_receive(:get_unit).and_return(0.0)
- @it.get_unit(:x).should be_within(MARGIN).of(0.0)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.0)
source_factory.should_receive(:get_unit).and_return(0.4)
- @it.get_unit(:x).should be_within(MARGIN).of(0.0)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.0)
source_factory.should_receive(:get_unit).and_return(0.51)
- @it.get_unit(:x).should be_within(MARGIN).of(1.0)
+ subject.get_unit(:x).should be_within(MARGIN).of(1.0)
source_factory.should_receive(:get_unit).and_return(0.9)
- @it.get_unit(:x).should be_within(MARGIN).of(1.0)
+ subject.get_unit(:x).should be_within(MARGIN).of(1.0)
source_factory.should_receive(:get_unit).and_return(1.0)
- @it.get_unit(:x).should be_within(MARGIN).of(1.0)
+ subject.get_unit(:x).should be_within(MARGIN).of(1.0)
end
end
View
36 spec/factories/sine_spec.rb
@@ -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/sine'
@@ -7,34 +7,34 @@
describe SineFactory do
- before :each do
- @it = SineFactory.new
+ subject do
+ SineFactory.new
end
it_should_behave_like "a factory"
it "loops between 0 and 1" do
- @it.interval = 1.0
- @it.get_unit(:x).should be_within(MARGIN).of(0.920)
- @it.get_unit(:x).should be_within(MARGIN).of(0.954)
- @it.get_unit(:x).should be_within(MARGIN).of(0.570)
- @it.get_unit(:x).should be_within(MARGIN).of(0.122)
- @it.get_unit(:x).should be_within(MARGIN).of(0.020)
- @it.get_unit(:x).should be_within(MARGIN).of(0.360)
+ subject.interval = 1.0
+ subject.get_unit(:x).should be_within(MARGIN).of(0.920)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.954)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.570)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.122)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.020)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.360)
end
it "can take a different interval" do
- @it.interval = 0.5
- @it.get_unit(:x).should be_within(MARGIN).of(0.740)
- @it.get_unit(:x).should be_within(MARGIN).of(0.920)
+ subject.interval = 0.5
+ subject.get_unit(:x).should be_within(MARGIN).of(0.740)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.920)
end
it "handles multiple keys" do
- @it.interval = 1.0
- @it.get_unit(:x).should be_within(MARGIN).of(0.920)
- @it.get_unit(:y).should be_within(MARGIN).of(0.920)
- @it.get_unit(:x).should be_within(MARGIN).of(0.954)
- @it.get_unit(:y).should be_within(MARGIN).of(0.954)
+ subject.interval = 1.0
+ subject.get_unit(:x).should be_within(MARGIN).of(0.920)
+ subject.get_unit(:y).should be_within(MARGIN).of(0.920)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.954)
+ subject.get_unit(:y).should be_within(MARGIN).of(0.954)
end
end
View
10 spec/factories/skip_spec.rb
@@ -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/skip'
@@ -7,16 +7,16 @@
describe SkipFactory do
- before :each do
- @it = SkipFactory.new
+ subject do
+ SkipFactory.new
end
it_should_behave_like "a factory"
it "generates only 0 or 1" do
- @it.odds = 0.1
+ subject.odds = 0.1
300.times do
- [0, 1].should include(@it.get_unit(:x))
+ [0, 1].should include(subject.get_unit(:x))
end
end
View
50 spec/factories/weighted_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require "rubyonacid/factories/weighted"
require "shared_factory_specs"
@@ -6,15 +6,15 @@
describe WeightedFactory do
- before :each do
- @it = WeightedFactory.new
+ subject do
+ WeightedFactory.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"
@@ -26,41 +26,41 @@
it "gives factories with higher weights more influence" do
factory1 = mock('Factory', :get_unit => 0.25)
factory2 = mock('Factory', :get_unit => 0.75)
- @it.source_factories << factory1
- @it.source_factories << factory2
- @it.get_unit(:x).should be_within(MARGIN).of(0.5)
- @it.weights[factory1] = 1.0
- @it.weights[factory2] = 2.0
- @it.get_unit(:x).should > 0.5
+ subject.source_factories << factory1
+ subject.source_factories << factory2
+ subject.get_unit(:x).should be_within(MARGIN).of(0.5)
+ subject.weights[factory1] = 1.0
+ subject.weights[factory2] = 2.0
+ subject.get_unit(:x).should > 0.5
end
it "multiplies factory values by weights when averaging" do
factory1 = mock('Factory', :get_unit => 0.2)
factory2 = mock('Factory', :get_unit => 0.4)
- @it.source_factories << factory1
- @it.source_factories << factory2
- @it.get_unit(:x).should be_within(MARGIN).of(0.3)
- @it.weights[factory1] = 2.0 #0.2 * 2.0 = 0.4
- @it.weights[factory2] = 4.0 #0.4 * 4.0 = 1.6
+ subject.source_factories << factory1
+ subject.source_factories << factory2
+ subject.get_unit(:x).should be_within(MARGIN).of(0.3)
+ subject.weights[factory1] = 2.0 #0.2 * 2.0 = 0.4
+ subject.weights[factory2] = 4.0 #0.4 * 4.0 = 1.6
#0.4 + 1.6 = 2.0
#2.0 / 6.0 (total weight) = 0.333
- @it.get_unit(:x).should be_within(MARGIN).of(0.333)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.333)
end
it "can handle 3 or more factories" do
factory1 = mock('Factory', :get_unit => 0.2)
factory2 = mock('Factory', :get_unit => 0.4)
factory3 = mock('Factory', :get_unit => 0.8)
- @it.source_factories << factory1
- @it.source_factories << factory2
- @it.source_factories << factory3
- @it.get_unit(:x).should be_within(MARGIN).of(0.4666)
- @it.weights[factory1] = 10.0 #0.2 * 10.0 = 2.0
- @it.weights[factory2] = 3.0 #0.4 * 3.0 = 1.2
- @it.weights[factory3] = 2.0 #0.8 * 2.0 = 1.6
+ subject.source_factories << factory1
+ subject.source_factories << factory2
+ subject.source_factories << factory3
+ subject.get_unit(:x).should be_within(MARGIN).of(0.4666)
+ subject.weights[factory1] = 10.0 #0.2 * 10.0 = 2.0
+ subject.weights[factory2] = 3.0 #0.4 * 3.0 = 1.2
+ subject.weights[factory3] = 2.0 #0.8 * 2.0 = 1.6
#2.0 + 1.2 + 1.6 = 4.8
#puts 4.8 / 15.0 (total weight) = 0.32
- @it.get_unit(:x).should be_within(MARGIN).of(0.32)
+ subject.get_unit(:x).should be_within(MARGIN).of(0.32)
end
end
View
74 spec/factory_spec.rb
@@ -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'
@@ -6,52 +6,52 @@
describe Factory do
- before :each do
- @it = Factory.new
+ subject do
+ Factory.new
end
describe "#choose" do
it "chooses an item from a list" do
- @it.stub!(:get_unit).and_return(0.0)
- @it.choose(:color, :red, :green, :blue).should == :red
- @it.stub!(:get_unit).and_return(1.0)
- @it.choose(:color, :red, :green, :blue).should == :blue
- @it.stub!(:get_unit).and_return(0.5)
- @it.choose(:color, :red, :green, :blue).should == :green
+ subject.stub!(:get_unit).and_return(0.0)
+ subject.choose(:color, :red, :green, :blue).should == :red
+ subject.stub!(:get_unit).and_return(1.0)
+ subject.choose(:color, :red, :green, :blue).should == :blue
+ subject.stub!(:get_unit).and_return(0.5)
+ subject.choose(:color, :red, :green, :blue).should == :green
end
it "matches a range of values for each list item" do
- @it.stub!(:get_unit).and_return(0.0)
- @it.choose(:foo, :a, :b, :c, :d).should == :a
- @it.stub!(:get_unit).and_return(0.24)
- @it.choose(:foo, :a, :b, :c, :d).should == :a
- @it.stub!(:get_unit).and_return(0.25)
- @it.choose(:foo, :a, :b, :c, :d).should == :b
- @it.stub!(:get_unit).and_return(0.49)
- @it.choose(:foo, :a, :b, :c, :d).should == :b
- @it.stub!(:get_unit).and_return(0.5)
- @it.choose(:foo, :a, :b, :c, :d).should == :c
- @it.stub!(:get_unit).and_return(0.74)
- @it.choose(:foo, :a, :b, :c, :d).should == :c
- @it.stub!(:get_unit).and_return(0.75)
- @it.choose(:foo, :a, :b, :c, :d).should == :d
- @it.stub!(:get_unit).and_return(1.0)
- @it.choose(:foo, :a, :b, :c, :d).should == :d
+ subject.stub!(:get_unit).and_return(0.0)
+ subject.choose(:foo, :a, :b, :c, :d).should == :a
+ subject.stub!(:get_unit).and_return(0.24)
+ subject.choose(:foo, :a, :b, :c, :d).should == :a
+ subject.stub!(:get_unit).and_return(0.25)
+ subject.choose(:foo, :a, :b, :c, :d).should == :b
+ subject.stub!(:get_unit).and_return(0.49)
+ subject.choose(:foo, :a, :b, :c, :d).should == :b
+ subject.stub!(:get_unit).and_return(0.5)
+ subject.choose(:foo, :a, :b, :c, :d).should == :c
+ subject.stub!(:get_unit).and_return(0.74)
+ subject.choose(:foo, :a, :b, :c, :d).should == :c
+ subject.stub!(:get_unit).and_return(0.75)
+ subject.choose(:foo, :a, :b, :c, :d).should == :d
+ subject.stub!(:get_unit).and_return(1.0)
+ subject.choose(:foo, :a, :b, :c, :d).should == :d
end
it "accepts multiple arguments" do
- @it.stub!(:get_unit).and_return(1.0)
- @it.choose(:color, :red, :green, :blue).should == :blue
+ subject.stub!(:get_unit).and_return(1.0)
+ subject.choose(:color, :red, :green, :blue).should == :blue
end
it "accepts arrays" do
- @it.stub!(:get_unit).and_return(1.0)
- @it.choose(:color, [:red, :green, :blue]).should == :blue
- @it.stub!(:get_unit).and_return(1.0)
- @it.choose(:color, [:red, :green, :blue], [:yellow, :orange]).should == :orange
- @it.stub!(:get_unit).and_return(0.0)
- @it.choose(:color, [:red, :green, :blue], [:yellow, :orange]).should == :red
+ subject.stub!(:get_unit).and_return(1.0)
+ subject.choose(:color, [:red, :green, :blue]).should == :blue
+ subject.stub!(:get_unit).and_return(1.0)
+ subject.choose(:color, [:red, :green, :blue], [:yellow, :orange]).should == :orange
+ subject.stub!(:get_unit).and_return(0.0)
+ subject.choose(:color, [:red, :green, :blue], [:yellow, :orange]).should == :red
end
end
@@ -61,15 +61,15 @@
it "calls #get_unit on each and averages results" do
factory1 = mock('Factory')
- @it.source_factories << factory1
+ subject.source_factories << factory1
factory2 = mock('Factory')
- @it.source_factories << factory2
+ subject.source_factories << factory2
factory3 = mock('Factory')
- @it.source_factories << factory3
+ subject.source_factories << factory3
factory1.should_receive(:get_unit).and_return(0.1)
factory2.should_receive(:get_unit).and_return(0.2)
factory3.should_receive(:get_unit).and_return(0.3)
- result = @it.get_unit(:x)
+ result = subject.get_unit(:x)
result.should be_within(MARGIN).of(0.2)
end
View
68 spec/shared_factory_specs.rb
@@ -6,7 +6,7 @@
describe "#get_unit" do
it "returns a value between 0.0 and 1.0 (inclusive) for a key" do
- value = @it.get_unit(:any_key)
+ value = subject.get_unit(:any_key)
value.should_not be_nil
value.should >= 0.0
value.should <= 1.0
@@ -15,52 +15,52 @@
describe "#within" do
it "allows setting a maximum" do
- @it.within(:any_key, 0.0, 1.0).should <= 1.0
- @it.within(:any_key, 0.0, 1.5).should <= 1.5
- @it.within(:any_key, 0.0, 2.0).should <= 2.0
- @it.within(:any_key, 0.0, 3.0).should <= 3.0
- @it.within(:any_key, 0.0, 10.0).should <= 10.0
- @it.within(:any_key, 0.0, 100.0).should <= 100.0
- @it.within(:any_key, 0.0, 1000.0).should <= 1000.0
- @it.within(:any_key, 0.0, 10000.0).should <= 10000.0
- @it.within(:any_key, -2.0, -1.0).should <= -1.0
- @it.within(:any_key, -10.0, -2.0).should <= -2.0
- @it.within(:any_key, -100.0, -10.0).should <= -10.0
+ subject.within(:any_key, 0.0, 1.0).should <= 1.0
+ subject.within(:any_key, 0.0, 1.5).should <= 1.5
+ subject.within(:any_key, 0.0, 2.0).should <= 2.0
+ subject.within(:any_key, 0.0, 3.0).should <= 3.0
+ subject.within(:any_key, 0.0, 10.0).should <= 10.0
+ subject.within(:any_key, 0.0, 100.0).should <= 100.0
+ subject.within(:any_key, 0.0, 1000.0).should <= 1000.0
+ subject.within(:any_key, 0.0, 10000.0).should <= 10000.0
+ subject.within(:any_key, -2.0, -1.0).should <= -1.0
+ subject.within(:any_key, -10.0, -2.0).should <= -2.0
+ subject.within(:any_key, -100.0, -10.0).should <= -10.0
end
it "allows setting a minimum" do
- @it.within(:any_key, 0.0, 1.0).should >= 0.0
- @it.within(:any_key, 1.5, 2.5).should >= 1.5
- @it.within(:any_key, 2.0, 10.0).should >= 2.0
- @it.within(:any_key, 3.0, 20.0).should >= 3.0
- @it.within(:any_key, 10.0, 30.0).should >= 10.0
- @it.within(:any_key, 100.0, 100000.0).should >= 100.0
- @it.within(:any_key, 1000.0, 100000.0).should >= 1000.0
- @it.within(:any_key, 10000.0, 100000.0).should >= 10000.0
- @it.within(:any_key, -1.0, 1.0).should >= -1.0
- @it.within(:any_key, -2.0, 1.0).should >= -2.0
- @it.within(:any_key, -10.0, 1.0).should >= -10.0
+ subject.within(:any_key, 0.0, 1.0).should >= 0.0
+ subject.within(:any_key, 1.5, 2.5).should >= 1.5
+ subject.within(:any_key, 2.0, 10.0).should >= 2.0
+ subject.within(:any_key, 3.0, 20.0).should >= 3.0
+ subject.within(:any_key, 10.0, 30.0).should >= 10.0
+ subject.within(:any_key, 100.0, 100000.0).should >= 100.0
+ subject.within(:any_key, 1000.0, 100000.0).should >= 1000.0
+ subject.within(:any_key, 10000.0, 100000.0).should >= 10000.0
+ subject.within(:any_key, -1.0, 1.0).should >= -1.0
+ subject.within(:any_key, -2.0, 1.0).should >= -2.0
+ subject.within(:any_key, -10.0, 1.0).should >= -10.0
end
end
describe "#get" do
it "allows setting a maximum" do
- @it.get(:a, :max => 2.0).should <= 2.0
- @it.get(:b, :max => 10.0).should <= 10.0
- @it.get(:c, :max => 100.0).should <= 100.0
- @it.get(:d, :max => 1000.0).should <= 1000.0
+ subject.get(:a, :max => 2.0).should <= 2.0
+ subject.get(:b, :max => 10.0).should <= 10.0
+ subject.get(:c, :max => 100.0).should <= 100.0
+ subject.get(:d, :max => 1000.0).should <= 1000.0
end
it "allows setting a minimum" do
- @it.get(:a, :min => 2.0).should >= 2.0
- @it.get(:b, :min => -1.0).should >= -1.0
- @it.get(:c, :min => -100.0).should >= -100.0
- @it.get(:d, :min => 1000.0).should >= 1000.0
+ subject.get(:a, :min => 2.0).should >= 2.0
+ subject.get(:b, :min => -1.0).should >= -1.0
+ subject.get(:c, :min => -100.0).should >= -100.0
+ subject.get(:d, :min => 1000.0).should >= 1000.0
end
it "uses a default minimum of 0.0" do
- @it.get(:a).should >= 0.0
- @it.get(:a, :max => 10.0).should >= 0.0
+ subject.get(:a).should >= 0.0
+ subject.get(:a, :max => 10.0).should >= 0.0
end
it "uses a default maximum of 1.0" do
- @it.get(:a).should <= 1.0
+ subject.get(:a).should <= 1.0
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.