Permalink
Browse files

+ field.integer(range) added

  • Loading branch information...
kschiess committed Sep 26, 2011
1 parent 7cac4b5 commit b37e0a7e64dd0d6091669c882f2d83fed68463fa
Showing with 13 additions and 1 deletion.
  1. +5 −0 lib/floor_manager/employee/dsl.rb
  2. +1 −1 spec/support/model/spy.rb
  3. +7 −0 spec/unit/floor_manager_spec.rb
@@ -18,6 +18,11 @@ def string(chars=10)
(0...chars).map{ ('a'..'z').to_a[rand(26)] }.join
})
end
+ def integer(range)
+ dsl._add_attribute AttributeAction::Block.new(field, proc {
+ range.first + rand(range.last-range.first)
+ })
+ end
end
def initialize(employee, filter=:none, &block)
@@ -1,7 +1,7 @@
class Spy
- attr_accessor :name, :opposite
+ attr_accessor :name, :opposite, :int
def self.build(attrs={})
new.tap { |instance|
@@ -180,6 +180,7 @@
FloorManager.define :any do |m|
any :random, :class => Spy do
name.string(10)
+ int.integer(5..10)
end
end
@@ -191,5 +192,11 @@
it { should match(/\w{10}/) }
end
+ context "random spies int" do
+ subject { env.build(:random).int }
+
+ it { should >= 5 }
+ it { should < 10 }
+ end
end
end

0 comments on commit b37e0a7

Please sign in to comment.