Skip to content
Browse files

Fix specs to work with Ruby 1.9.3+

The ability to refer to constants in an included module was actually a bug
in Ruby 1.9.2, so the specs were failing on later versions where this bug has
been fixed.

The solution is to define the example blocks inside the module itself, since
that's the only place where the unqualified constants should be visible.

rspec/rspec-core#506
http://bugs.ruby-lang.org/issues/5657
https://twitter.com/dchelimsky/status/185335729738616833
  • Loading branch information...
1 parent 6e81157 commit d89051eaaff744e81b191973160ab149432d0bbf @tomstuart committed Mar 29, 2012
Showing with 77 additions and 77 deletions.
  1. +77 −77 spec/nothing_spec.rb
View
154 spec/nothing_spec.rb
@@ -1,103 +1,103 @@
require 'spec_helper'
-describe Nothing do
- include Nothing
-
- describe 'natural numbers' do
- specify { pending { ZERO.should represent 0 } }
- specify { pending { ONE.should represent 1 } }
- specify { pending { TWO.should represent 2 } }
- specify { pending { THREE.should represent 3 } }
-
- specify { pending { TIMES[representation_of 3][-> s { s + 'o' }]['hell'].should == 'hellooo' } }
- specify { pending { INCREMENT[representation_of 2].should represent 2 + 1 } }
- specify { pending { ADD[representation_of 2][representation_of 3].should represent 2 + 3 } }
- specify { pending { MULTIPLY[representation_of 2][representation_of 3].should represent 2 * 3 } }
- specify { pending { POWER[representation_of 2][representation_of 3].should represent 2 ** 3 } }
- specify { pending { DECREMENT[representation_of 3].should represent 3 - 1 } }
- specify { pending { SUBTRACT[representation_of 3][representation_of 2].should represent 3 - 2 } }
-
- context 'with booleans' do
- (0..3).each do |n|
- specify { pending { IS_ZERO[representation_of n].should represent n.zero? } }
- specify { pending { IS_LESS_OR_EQUAL[representation_of n][representation_of 2].should represent n <= 2 } }
- specify { pending { IS_EQUAL[representation_of n][representation_of 2].should represent n == 2 } }
+module Nothing
+ describe Nothing do
+ describe 'natural numbers' do
+ specify { pending { ZERO.should represent 0 } }
+ specify { pending { ONE.should represent 1 } }
+ specify { pending { TWO.should represent 2 } }
+ specify { pending { THREE.should represent 3 } }
+
+ specify { pending { TIMES[representation_of 3][-> s { s + 'o' }]['hell'].should == 'hellooo' } }
+ specify { pending { INCREMENT[representation_of 2].should represent 2 + 1 } }
+ specify { pending { ADD[representation_of 2][representation_of 3].should represent 2 + 3 } }
+ specify { pending { MULTIPLY[representation_of 2][representation_of 3].should represent 2 * 3 } }
+ specify { pending { POWER[representation_of 2][representation_of 3].should represent 2 ** 3 } }
+ specify { pending { DECREMENT[representation_of 3].should represent 3 - 1 } }
+ specify { pending { SUBTRACT[representation_of 3][representation_of 2].should represent 3 - 2 } }
+
+ context 'with booleans' do
+ (0..3).each do |n|
+ specify { pending { IS_ZERO[representation_of n].should represent n.zero? } }
+ specify { pending { IS_LESS_OR_EQUAL[representation_of n][representation_of 2].should represent n <= 2 } }
+ specify { pending { IS_EQUAL[representation_of n][representation_of 2].should represent n == 2 } }
+ end
end
- end
- context 'with recursion' do
- (0..5).zip([1, 1, 2, 6, 24, 120]) do |n, n_factorial|
- specify { pending { FACTORIAL[representation_of n].should represent n_factorial } }
- end
+ context 'with recursion' do
+ (0..5).zip([1, 1, 2, 6, 24, 120]) do |n, n_factorial|
+ specify { pending { FACTORIAL[representation_of n].should represent n_factorial } }
+ end
- [0, 1, 11, 27].product([1, 3, 11]) do |m, n|
- specify { pending { DIV[representation_of m][representation_of n].should represent m / n } }
- specify { pending { MOD[representation_of m][representation_of n].should represent m % n } }
+ [0, 1, 11, 27].product([1, 3, 11]) do |m, n|
+ specify { pending { DIV[representation_of m][representation_of n].should represent m / n } }
+ specify { pending { MOD[representation_of m][representation_of n].should represent m % n } }
+ end
end
- end
- context 'with lists' do
- specify { pending { TO_DIGITS[representation_of 42].should represent [4, 2] } }
- end
+ context 'with lists' do
+ specify { pending { TO_DIGITS[representation_of 42].should represent [4, 2] } }
+ end
- context 'with strings' do
- specify { pending { TO_STRING[representation_of 42].should represent '42' } }
+ context 'with strings' do
+ specify { pending { TO_STRING[representation_of 42].should represent '42' } }
+ end
end
- end
- describe 'booleans' do
- specify { pending { TRUE.should represent true } }
- specify { pending { FALSE.should represent false } }
+ describe 'booleans' do
+ specify { pending { TRUE.should represent true } }
+ specify { pending { FALSE.should represent false } }
- let(:foo) { Object.new }
- let(:bar) { Object.new }
+ let(:foo) { Object.new }
+ let(:bar) { Object.new }
- [true, false].each do |b|
- specify { pending { IF[representation_of b][foo][bar].should equal(if b then foo else bar end) } }
- specify { pending { NOT[representation_of b].should represent !b } }
+ [true, false].each do |b|
+ specify { pending { IF[representation_of b][foo][bar].should equal(if b then foo else bar end) } }
+ specify { pending { NOT[representation_of b].should represent !b } }
- [true, false].each do |a|
- specify { pending { AND[representation_of a][representation_of b].should represent a && b } }
- specify { pending { OR[representation_of a][representation_of b].should represent a || b } }
+ [true, false].each do |a|
+ specify { pending { AND[representation_of a][representation_of b].should represent a && b } }
+ specify { pending { OR[representation_of a][representation_of b].should represent a || b } }
+ end
end
end
- end
- describe 'pairs' do
- specify { pending { PAIR[representation_of 3][representation_of 5].should represent Pair.new(3, 5) } }
+ describe 'pairs' do
+ specify { pending { PAIR[representation_of 3][representation_of 5].should represent Pair.new(3, 5) } }
- let(:foo) { Object.new }
- let(:bar) { Object.new }
+ let(:foo) { Object.new }
+ let(:bar) { Object.new }
- specify { pending { LEFT[PAIR[foo][bar]].should equal(foo) } }
- specify { pending { RIGHT[PAIR[foo][bar]].should equal(bar) } }
- end
-
- describe 'lists' do
- specify { pending { EMPTY.should represent [] } }
- specify { pending { UNSHIFT[representation_of [2, 3]][representation_of 1].should represent [1, 2, 3] } }
+ specify { pending { LEFT[PAIR[foo][bar]].should equal(foo) } }
+ specify { pending { RIGHT[PAIR[foo][bar]].should equal(bar) } }
+ end
- specify { pending { IS_EMPTY[representation_of []].should represent true } }
- specify { pending { IS_EMPTY[representation_of [1]].should represent false } }
- specify { pending { FIRST[representation_of [1, 2, 3]].should represent 1 } }
- specify { pending { REST[representation_of [1, 2, 3]].should represent [2, 3] } }
+ describe 'lists' do
+ specify { pending { EMPTY.should represent [] } }
+ specify { pending { UNSHIFT[representation_of [2, 3]][representation_of 1].should represent [1, 2, 3] } }
- specify { pending { RANGE[representation_of 2][representation_of 8].should represent [2, 3, 4, 5, 6, 7, 8] } }
- specify { pending { SUM[representation_of [2, 2, 3]].should represent 7 } }
- specify { pending { PRODUCT[representation_of [2, 2, 3]].should represent 12 } }
- specify { pending { CONCAT[representation_of [1, 2]][representation_of [3, 2]].should represent [1, 2, 3, 2] } }
- specify { pending { PUSH[representation_of [1, 2]][representation_of 3].should represent [1, 2, 3] } }
- specify { pending { REVERSE[representation_of [1, 2, 3]].should represent [3, 2, 1] } }
+ specify { pending { IS_EMPTY[representation_of []].should represent true } }
+ specify { pending { IS_EMPTY[representation_of [1]].should represent false } }
+ specify { pending { FIRST[representation_of [1, 2, 3]].should represent 1 } }
+ specify { pending { REST[representation_of [1, 2, 3]].should represent [2, 3] } }
- specify { pending { INCREMENT_ALL[representation_of [1, 2, 3]].should represent [2, 3, 4] } }
- specify { pending { DOUBLE_ALL[representation_of [1, 2, 3]].should represent [2, 4, 6] } }
- end
+ specify { pending { RANGE[representation_of 2][representation_of 8].should represent [2, 3, 4, 5, 6, 7, 8] } }
+ specify { pending { SUM[representation_of [2, 2, 3]].should represent 7 } }
+ specify { pending { PRODUCT[representation_of [2, 2, 3]].should represent 12 } }
+ specify { pending { CONCAT[representation_of [1, 2]][representation_of [3, 2]].should represent [1, 2, 3, 2] } }
+ specify { pending { PUSH[representation_of [1, 2]][representation_of 3].should represent [1, 2, 3] } }
+ specify { pending { REVERSE[representation_of [1, 2, 3]].should represent [3, 2, 1] } }
- describe 'FizzBuzz' do
- def fizzbuzz(m)
- (1..m).map { |n| (n % 15).zero? ? 'FizzBuzz' : (n % 3).zero? ? 'Fizz' : (n % 5).zero? ? 'Buzz' : n.to_s }
+ specify { pending { INCREMENT_ALL[representation_of [1, 2, 3]].should represent [2, 3, 4] } }
+ specify { pending { DOUBLE_ALL[representation_of [1, 2, 3]].should represent [2, 4, 6] } }
end
- specify { pending { FIZZBUZZ[representation_of 30].should represent fizzbuzz(30) } }
+ describe 'FizzBuzz' do
+ def fizzbuzz(m)
+ (1..m).map { |n| (n % 15).zero? ? 'FizzBuzz' : (n % 3).zero? ? 'Fizz' : (n % 5).zero? ? 'Buzz' : n.to_s }
+ end
+
+ specify { pending { FIZZBUZZ[representation_of 30].should represent fizzbuzz(30) } }
+ end
end
end

0 comments on commit d89051e

Please sign in to comment.
Something went wrong with that request. Please try again.