diff options
Diffstat (limited to 'spec/ruby/library')
-rw-r--r-- | spec/ruby/library/date/day_spec.rb | 5 | ||||
-rw-r--r-- | spec/ruby/library/date/month_spec.rb | 5 | ||||
-rw-r--r-- | spec/ruby/library/date/next_month_spec.rb | 14 | ||||
-rw-r--r-- | spec/ruby/library/date/prev_day_spec.rb | 14 | ||||
-rw-r--r-- | spec/ruby/library/date/prev_month_spec.rb | 14 | ||||
-rw-r--r-- | spec/ruby/library/date/year_spec.rb | 5 | ||||
-rw-r--r-- | spec/ruby/library/fiber/current_spec.rb | 20 | ||||
-rw-r--r-- | spec/ruby/library/set/sortedset/add_spec.rb | 8 | ||||
-rw-r--r-- | spec/ruby/library/set/sortedset/initialize_spec.rb | 6 | ||||
-rw-r--r-- | spec/ruby/library/set/sortedset/to_a_spec.rb | 13 |
10 files changed, 84 insertions, 20 deletions
diff --git a/spec/ruby/library/date/day_spec.rb b/spec/ruby/library/date/day_spec.rb index 7dfca4d77c..d3561d802d 100644 --- a/spec/ruby/library/date/day_spec.rb +++ b/spec/ruby/library/date/day_spec.rb @@ -2,5 +2,8 @@ require File.expand_path('../../../spec_helper', __FILE__) require 'date' describe "Date#day" do - it "needs to be reviewed for spec completeness" + it "returns the day" do + d = Date.new(2000, 7, 1).day + d.should == 1 + end end diff --git a/spec/ruby/library/date/month_spec.rb b/spec/ruby/library/date/month_spec.rb index 7a98f572b6..ea35430d6b 100644 --- a/spec/ruby/library/date/month_spec.rb +++ b/spec/ruby/library/date/month_spec.rb @@ -2,5 +2,8 @@ require File.expand_path('../../../spec_helper', __FILE__) require 'date' describe "Date#month" do - it "needs to be reviewed for spec completeness" + it "returns the month" do + m = Date.new(2000, 7, 1).month + m.should == 7 + end end diff --git a/spec/ruby/library/date/next_month_spec.rb b/spec/ruby/library/date/next_month_spec.rb new file mode 100644 index 0000000000..22699a39a5 --- /dev/null +++ b/spec/ruby/library/date/next_month_spec.rb @@ -0,0 +1,14 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require 'date' + +describe "Date#next_month" do + it "returns the next month" do + d = Date.new(2000, 7, 1).next_month + d.should == Date.new(2000, 8, 1) + end + + it "returns three months later" do + d = Date.new(2000, 7, 1).next_month(3) + d.should == Date.new(2000, 10, 1) + end +end diff --git a/spec/ruby/library/date/prev_day_spec.rb b/spec/ruby/library/date/prev_day_spec.rb new file mode 100644 index 0000000000..8a42824154 --- /dev/null +++ b/spec/ruby/library/date/prev_day_spec.rb @@ -0,0 +1,14 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require 'date' + +describe "Date#prev_day" do + it "returns previous day" do + d = Date.new(2000, 7, 2).prev_day + d.should == Date.new(2000, 7, 1) + end + + it "returns three days ago" do + d = Date.new(2000, 7, 4).prev_day(3) + d.should == Date.new(2000, 7, 1) + end +end diff --git a/spec/ruby/library/date/prev_month_spec.rb b/spec/ruby/library/date/prev_month_spec.rb new file mode 100644 index 0000000000..eaf7f67ee0 --- /dev/null +++ b/spec/ruby/library/date/prev_month_spec.rb @@ -0,0 +1,14 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require 'date' + +describe "Date#prev_month" do + it "returns previous month" do + d = Date.new(2000, 9, 1).prev_month + d.should == Date.new(2000, 8, 1) + end + + it "returns three months ago" do + d = Date.new(2000, 10, 1).prev_month(3) + d.should == Date.new(2000, 7, 1) + end +end diff --git a/spec/ruby/library/date/year_spec.rb b/spec/ruby/library/date/year_spec.rb index cca95dbe2a..4720ddcd9a 100644 --- a/spec/ruby/library/date/year_spec.rb +++ b/spec/ruby/library/date/year_spec.rb @@ -2,5 +2,8 @@ require File.expand_path('../../../spec_helper', __FILE__) require 'date' describe "Date#year" do - it "needs to be reviewed for spec completeness" + it "returns the year" do + y = Date.new(2000, 7, 1).year + y.should == 2000 + end end diff --git a/spec/ruby/library/fiber/current_spec.rb b/spec/ruby/library/fiber/current_spec.rb index 48345fb7cf..fd68cd52ea 100644 --- a/spec/ruby/library/fiber/current_spec.rb +++ b/spec/ruby/library/fiber/current_spec.rb @@ -10,7 +10,7 @@ with_feature :fiber_library do # We can always transfer to the root Fiber; it will never die 5.times do root.transfer.should be_nil - root.alive?.should_not be_false #Workaround for bug #1547 + root.alive?.should be_true end end @@ -19,39 +19,31 @@ with_feature :fiber_library do this = Fiber.current this.should be_an_instance_of(Fiber) this.should == fiber - this.alive?.should_not be_false # Workaround for bug #1547 + this.alive?.should be_true end fiber.resume end it "returns the current Fiber when called from a Fiber that transferred to another" do - states = [] fiber = Fiber.new do states << :fiber this = Fiber.current this.should be_an_instance_of(Fiber) - this.should === fiber - this.alive?.should_not be_false # Workaround for bug #1547 + this.should == fiber + this.alive?.should be_true end fiber2 = Fiber.new do states << :fiber2 fiber.transfer - this = Fiber.current - this.should be_an_instance_of(Fiber) - this.should === fiber2 - this.alive?.should_not be_false # Workaround for bug #1547 + flunk end fiber3 = Fiber.new do states << :fiber3 fiber2.transfer - this = Fiber.current - this.should be_an_instance_of(Fiber) - this.should === fiber3 - this.alive?.should_not be_false # Workaround for bug #1547 - fiber2.transfer + flunk end fiber3.resume diff --git a/spec/ruby/library/set/sortedset/add_spec.rb b/spec/ruby/library/set/sortedset/add_spec.rb index bdc5c077d8..df291561a8 100644 --- a/spec/ruby/library/set/sortedset/add_spec.rb +++ b/spec/ruby/library/set/sortedset/add_spec.rb @@ -7,9 +7,15 @@ describe "SortedSet#add" do it "takes only values which responds <=>" do obj = mock('no_comparison_operator') - obj.should_receive(:respond_to?).with(:<=>).and_return(false) + obj.stub!(:respond_to?).with(:<=>).and_return(false) lambda { SortedSet["hello"].add(obj) }.should raise_error(ArgumentError) end + + it "raises on incompatible <=> comparison" do + # Use #to_a here as elements are sorted only when needed. + # Therefore the <=> incompatibility is only noticed on sorting. + lambda { SortedSet['1', '2'].add(3).to_a }.should raise_error(ArgumentError) + end end describe "SortedSet#add?" do diff --git a/spec/ruby/library/set/sortedset/initialize_spec.rb b/spec/ruby/library/set/sortedset/initialize_spec.rb index 04ad908667..77ee23e851 100644 --- a/spec/ruby/library/set/sortedset/initialize_spec.rb +++ b/spec/ruby/library/set/sortedset/initialize_spec.rb @@ -21,4 +21,10 @@ describe "SortedSet#initialize" do s.should include(4) s.should include(9) end + + it "raises on incompatible <=> comparison" do + # Use #to_a here as elements are sorted only when needed. + # Therefore the <=> incompatibility is only noticed on sorting. + lambda { SortedSet.new(['00', nil]).to_a }.should raise_error(ArgumentError) + end end diff --git a/spec/ruby/library/set/sortedset/to_a_spec.rb b/spec/ruby/library/set/sortedset/to_a_spec.rb index f288cfb9d2..77deb17731 100644 --- a/spec/ruby/library/set/sortedset/to_a_spec.rb +++ b/spec/ruby/library/set/sortedset/to_a_spec.rb @@ -2,7 +2,16 @@ require File.expand_path('../../../../spec_helper', __FILE__) require 'set' describe "SortedSet#to_a" do - it "returns an array containing elements of self" do - SortedSet[1, 2, 3].to_a.sort.should == [1, 2, 3] + it "returns an array containing elements" do + set = SortedSet.new [1, 2, 3] + set.to_a.should == [1, 2, 3] + end + + it "returns a sorted array containing elements" do + set = SortedSet[2, 3, 1] + set.to_a.should == [1, 2, 3] + + set = SortedSet.new [5, 6, 4, 4] + set.to_a.should == [4, 5, 6] end end |