Permalink
Browse files

Made .seen spec use new helper method; refactored.

Rather than creating an Array of Eye objects, one for each type, in the specs
themselves, add a helper method to do this.
  • Loading branch information...
1 parent 7d2aa36 commit 7e49026021fe4f74a3b711bfe44183ac37d20f2f @runpaint committed Apr 27, 2009
Showing with 14 additions and 10 deletions.
  1. +7 −10 spec/eye/seen_spec.rb
  2. +7 −0 spec/spec_helper.rb
View
@@ -1,36 +1,33 @@
describe "Eye.seen?" do
-
- before(:each) do
- @eyes = [:array, :hash, :bloom_filter].map{|t| Eye.new(:type => t)}
- end
+ include HelperMethods
it "is a method" do
- @eyes.each do |eye|
+ eyes.each do |eye|
eye.should.respond_to? :seen?
end
end
it "takes a single argument" do
- @eyes.each do |eye|
+ eyes.each do |eye|
lambda{eye.seen?("string")}.should_not raise_error
end
end
it "raises an ArgumentError if called without arguments" do
- @eyes.each do |eye|
+ eyes.each do |eye|
lambda{eye.seen?}.should raise_error(ArgumentError)
end
end
it "raises an ArgumentError if called with more than one argument" do
- @eyes.each do |eye|
+ eyes.each do |eye|
lambda{eye.seen?(1,2)}.should raise_error(ArgumentError)
lambda{eye.seen?("str",['g'],"bar")}.should raise_error(ArgumentError)
end
end
it "returns true if .see(obj) has been called previously" do
- @eyes.each do |eye|
+ eyes.each do |eye|
['Kim', 'http://example.com/'].each do |obj|
eye.see obj
eye.seen?(obj).should == true
@@ -40,7 +37,7 @@
end
it "returns false unless .see(obj) has been called previously" do
- @eyes.each do |eye|
+ eyes.each do |eye|
['The Tao of Pooh', 29, 30.3].each do |obj|
eye.seen?(obj).should == false
end
View
@@ -4,6 +4,13 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'eye'
+module HelperMethods
+ TYPES = [:bloom_filter, :array, :hash]
+ def eyes
+ TYPES.map{|t| Eye.new(:type => t)}
+ end
+end
+
Spec::Runner.configure do |config|
end

0 comments on commit 7e49026

Please sign in to comment.