Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

specs migrated to rspec2.3 #11

Merged
21 commits merged into from

2 participants

Chip Malice Clifford Heath
Chip Malice

hi per our conv in the message thread here's the chnges to bring the specs up to rspec2.3 to go green on ruby 1.8.7

hipe added some commits
Chip Malice hipe Refactor :shared => true to shared_examples_for() 48156a4
Chip Malice hipe Change Gemfile to specify rspec 2.3.0 and not 1.3.0
  * the next few commits will be broken as we progressively make changes
bfac1ce
Chip Malice hipe Change Rakefile to work with rspec 2.3
  @todo - what did libs() do?
8055209
Chip Malice hipe Change spec_helper to work with rspec2.3
  * all tests are broken now!
  * rather than registering compiler & runtime with example group,
      we call include() and extend() on the config object
7f2eb0d
Chip Malice hipe Change shared exmaple group in palidromic fixture to be valid for rsp…
…ec 2.3

  * all tests still broken!
4df61e5
Chip Malice hipe Change one last :shared=>true to be a shared_example_group
  * now the tests aren't fully broken: (359 examples, 139 failures)
  * we will be changing this one probably to be a shared context
3b48f1b
Chip Malice hipe Merge branch 'master' of github.com:hipe/treetop into rspec2.3 6e466a9
Chip Malice hipe Fix how we require helper file so it doesn't get loaded twice
  (407 examples, 144 failures)
df9a998
Chip Malice hipe Change shared example with filter to be a SharedContext for rspec 2.3
  in rspec 2.3, it looks like shared example groups will not allow
  you to specify before filters that descend down to children, only
  to specify examples.  Rather, we need to create a SharedContext module
  and include it in the example groups.

  @todo refactor after 'deterministic' migration is done
eacbdbe
Chip Malice hipe Refactor insert_and_delete_node_spec for rspec 2.3
  Create the @deterministic tag to aide in running focused tests.
  (44 examples, 0 failures) (Run filtered using {:deterministic=>true})
e076b34
Chip Malice hipe Create temporary tag to show the currently broken spec
  (108 examples, 42 failures) (Run filtered using {:deterministic2=>true})
  Note that because of the underlying pseudo-randomness of the calls,
  the number of errors itself is non-deterministic
ec2935d
Chip Malice hipe Just to be sure this change is necessary, demonstrate it
(above and below this commit is the migration happending that demonstrates this.)
890f77b
Chip Malice hipe Fantatic! refactor for rspec 2.3
in spec_helper.rb just comment out unused code

in insert_spec.rb,
changing one line wins us dozens of greens
(108 examples, 0 failures) (Run filtered using {:deterministic2=>true})
def51a7
Chip Malice hipe Determinsitic tagged exmaples: 152 examples, 0 failures c607966
Chip Malice hipe Add palindromic tag to show 96/96 failures before refactor
(96 examples, 96 failures) (Run filtered using {:palindromic=>true})
be153ed
Chip Malice hipe Refactor palindromic shared context to work with rspec2.3
Make a temporary, more focused 'palindromic2' tag (@todo temporary)
(26 examples, 0 failures) (Run filtered using {:palindromic2=>true})

@smell is it clear enough what is going on? can it be cleaned up?
48e5fc9
Chip Malice hipe Palindromic is all green!
(96 examples, 0 failures) (Run filtered using {:palindromic=>true})
a4aeb47
Chip Malice hipe Refactor: remove unused shared example (became shared context) ff4c6bd
Chip Malice hipe Refactor to remove unnecessary (empty) shared example that became a S…
…haredContext
7f60a6f
Chip Malice hipe Create @mutlbyte tag showing 3 examples, 3 failures d9f5cdb
Chip Malice hipe Restore $KCODE setting for multibyte support that rspec used to do
(3 examples, 0 failures) (Run filtered using {:multibyte=>true})

@todo 1.9 ?

rspec 1.3.1 used to set $KCODE='u' in one place which activated the
activesuport wrapper for multibyte chars when calling String#mb_chars
bc554fd
Clifford Heath
Collaborator

I've merged this on my master branch, but not yet pushed. It works with any RSpec 2, not just 2.3, so I loosened up the Gemfile a little. rr still fails badly on 1.9.2. When you were looking at the IntervalSkipList tests, did you get your head around the way rr is being used for mocking? Because if the author doesn't bring it up to 1.9.2 soon, we might need to ditch rr and refactor using another mocking framework. I haven't looked, but I doubt it's hard.

Chip Malice

This is all very exciting! I did see that the mocking lib being used to turn next_node_height() into a thing that returns a series of (deterministic) integers rather than the randomness. I find it likely that we could bring rr up to 1.9.2 but the fact that it hasn't already doesn't bode well for the health of the project I think. But i'm not sure whether that is smarter than b) switching to a different mock lib (factory girl/machinist?) or just writing the five lines of code we would need to implement stub() ourselves in spec_helper.rb or something. What sounds smartest to you? I'll read up on rr. Thanks!

Chip Malice

rspec 2.3 if not 2.0 has mocks i'll probably go this route if it meets the requirements unless u would rather something else! thx

Chip Malice

hi i hope to work on this in the next seven days or so i'm hoping it will only take like 2-4 hours or so to determine if the mocking facilities in rspec2 can work for the minimal mocking needs of the specs

Clifford Heath
Collaborator

Did you get anywhere with the mocking stuff?

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 14, 2010
  1. Chip Malice
Commits on Dec 15, 2010
  1. Chip Malice

    Change Gemfile to specify rspec 2.3.0 and not 1.3.0

    hipe authored
      * the next few commits will be broken as we progressively make changes
  2. Chip Malice

    Change Rakefile to work with rspec 2.3

    hipe authored
      @todo - what did libs() do?
  3. Chip Malice

    Change spec_helper to work with rspec2.3

    hipe authored
      * all tests are broken now!
      * rather than registering compiler & runtime with example group,
          we call include() and extend() on the config object
  4. Chip Malice

    Change shared exmaple group in palidromic fixture to be valid for rsp…

    hipe authored
    …ec 2.3
    
      * all tests still broken!
  5. Chip Malice

    Change one last :shared=>true to be a shared_example_group

    hipe authored
      * now the tests aren't fully broken: (359 examples, 139 failures)
      * we will be changing this one probably to be a shared context
  6. Chip Malice
  7. Chip Malice

    Fix how we require helper file so it doesn't get loaded twice

    hipe authored
      (407 examples, 144 failures)
  8. Chip Malice

    Change shared example with filter to be a SharedContext for rspec 2.3

    hipe authored
      in rspec 2.3, it looks like shared example groups will not allow
      you to specify before filters that descend down to children, only
      to specify examples.  Rather, we need to create a SharedContext module
      and include it in the example groups.
    
      @todo refactor after 'deterministic' migration is done
  9. Chip Malice

    Refactor insert_and_delete_node_spec for rspec 2.3

    hipe authored
      Create the @deterministic tag to aide in running focused tests.
      (44 examples, 0 failures) (Run filtered using {:deterministic=>true})
  10. Chip Malice

    Create temporary tag to show the currently broken spec

    hipe authored
      (108 examples, 42 failures) (Run filtered using {:deterministic2=>true})
      Note that because of the underlying pseudo-randomness of the calls,
      the number of errors itself is non-deterministic
  11. Chip Malice

    Just to be sure this change is necessary, demonstrate it

    hipe authored
    (above and below this commit is the migration happending that demonstrates this.)
  12. Chip Malice

    Fantatic! refactor for rspec 2.3

    hipe authored
    in spec_helper.rb just comment out unused code
    
    in insert_spec.rb,
    changing one line wins us dozens of greens
    (108 examples, 0 failures) (Run filtered using {:deterministic2=>true})
  13. Chip Malice
  14. Chip Malice

    Add palindromic tag to show 96/96 failures before refactor

    hipe authored
    (96 examples, 96 failures) (Run filtered using {:palindromic=>true})
  15. Chip Malice

    Refactor palindromic shared context to work with rspec2.3

    hipe authored
    Make a temporary, more focused 'palindromic2' tag (@todo temporary)
    (26 examples, 0 failures) (Run filtered using {:palindromic2=>true})
    
    @smell is it clear enough what is going on? can it be cleaned up?
  16. Chip Malice

    Palindromic is all green!

    hipe authored
    (96 examples, 0 failures) (Run filtered using {:palindromic=>true})
  17. Chip Malice
  18. Chip Malice
  19. Chip Malice
  20. Chip Malice

    Restore $KCODE setting for multibyte support that rspec used to do

    hipe authored
    (3 examples, 0 failures) (Run filtered using {:multibyte=>true})
    
    @todo 1.9 ?
    
    rspec 1.3.1 used to set $KCODE='u' in one place which activated the
    activesuport wrapper for multibyte chars when calling String#mb_chars
This page is out of date. Refresh to see the latest.
2  Gemfile
View
@@ -7,7 +7,7 @@ group :development do
gem "bluecloth"
gem "erector", "~> 0.8"
gem "i18n", "~> 0.5.0"
- gem "rspec", "~> 1.3.0"
+ gem "rspec", "~> 2.3.0"
gem "rr", "~> 0.10.2"
gem "ruby-debug"
end
6 Rakefile
View
@@ -1,12 +1,12 @@
require 'rubygems'
require 'rake'
require 'rake/gempackagetask'
-require 'spec/rake/spectask'
+require 'rspec/core/rake_task'
task :default => :spec
-Spec::Rake::SpecTask.new do |t|
+RSpec::Core::RakeTask.new do |t|
t.pattern = 'spec/**/*spec.rb'
- t.libs << 'spec'
+ # t.libs << 'spec' # @todo not sure what this did in the original rspec 1.3
end
load "./treetop.gemspec"
13 spec/compiler/multibyte_chars_spec.rb
View
@@ -4,21 +4,23 @@
require 'spec_helper'
module MultibyteCharsSpec
- describe "an anything symbol" do
+ describe "an anything symbol", :multibyte => true do
testing_expression '.'
it "matches an UTF-8 character" do
parse_multibyte("ø").should_not be_nil
end
end
-
- describe "A character class containing UTF-8 characters" do
+
+ describe "A character class containing UTF-8 characters", :multibyte => true do
testing_expression "[æøå]"
it "recognizes the UTF-8 characters" do
parse_multibyte("ø").should_not be_nil
end
end
-
- describe "a character class repetition containing UTF-8 characters mixed with other expressions" do
+
+ describe( "a character class repetition containing UTF-8 characters mixed with other expressions",
+ :multibyte => true
+ ) do
testing_expression '[æøå]+ "a"'
it "lazily instantiates a node for the character" do
result = parse_multibyte('æøåa')
@@ -34,5 +36,4 @@ module MultibyteCharsSpec
result.elements[1].text_value == "a"
end
end
-
end
4 spec/runtime/interval_skip_list/delete_spec.rb
View
@@ -4,8 +4,8 @@ class IntervalSkipList
public :insert_node, :delete_node, :head, :nodes
end
-describe IntervalSkipList do
- it_should_behave_like "the palindromic fixture"
+describe IntervalSkipList, :palindromic => true do
+ include PalindromicFixtureSharedContext
describe " when :c is deleted" do
before do
6 spec/runtime/interval_skip_list/expire_range_spec.rb
View
@@ -1,7 +1,7 @@
require 'runtime/interval_skip_list/spec_helper'
-describe IntervalSkipList do
- it_should_behave_like "the palindromic fixture"
+describe IntervalSkipList, :palindromic => true do
+ include PalindromicFixtureSharedContext
describe "#overlapping" do
it "returns intervals :d, :e, :f, and :g for 7..9" do
@@ -137,7 +137,7 @@
end
describe "when 4..4 is expired with a length change of 2" do
- before do
+ before do
list.expire(4..4, 2)
end
26 spec/runtime/interval_skip_list/insert_and_delete_node_spec.rb
View
@@ -1,18 +1,18 @@
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'runtime/interval_skip_list/spec_helper'
-describe "it is non-empty", :shared => true do
+shared_examples_for "it is non-empty" do
specify "#empty? returns false" do
list.should_not be_empty
end
end
-describe "#nodes is an array of the three inserted nodes in key order", :shared => true do
+shared_examples_for "#nodes is an array of the three inserted nodes in key order" do
specify "#nodes is an array of the three inserted nodes in key order" do
list.nodes.should == inserted_nodes.sort_by(&:key)
end
end
-describe "it has nil forward pointers", :shared => true do
+shared_examples_for "it has nil forward pointers" do
it "has nil forward pointers" do
inserted_node.forward.each do |next_pointer|
next_pointer.should be_nil
@@ -22,7 +22,7 @@
describe IntervalSkipList do
attr_reader :list
-
+
before do
@list = IntervalSkipList.new
end
@@ -55,14 +55,14 @@
end
end
- describe " when 1 has been inserted" do
+ describe " when 1 has been inserted", :deterministic => true do
attr_reader :inserted_node, :inserted_nodes
def expected_node_heights
[1]
end
- it_should_behave_like "#next_node_height is deterministic"
+ include NextNodeHeightIsDeterministicSharedContext
before do
@inserted_node = list.insert_node(1)
@@ -115,14 +115,14 @@ def expected_node_heights
end
end
- describe " when 1 and 3 have been inserted in order" do
+ describe " when 1 and 3 have been inserted in order", :deterministic => true do
attr_reader :inserted_nodes
def expected_node_heights
[1, 2]
end
- it_should_behave_like "#next_node_height is deterministic"
+ include NextNodeHeightIsDeterministicSharedContext
before do
@inserted_nodes = []
@@ -212,14 +212,14 @@ def expected_node_heights
end
end
- describe " when 1, 3 and 7 have been inserted in order" do
+ describe " when 1, 3 and 7 have been inserted in order", :deterministic => true do
attr_reader :inserted_nodes
def expected_node_heights
[1, 2, 1]
end
- it_should_behave_like "#next_node_height is deterministic"
+ include NextNodeHeightIsDeterministicSharedContext
before do
@inserted_nodes = []
@@ -309,14 +309,14 @@ def expected_node_heights
end
end
- describe " when 7, 1 and 3 have been inserted in order" do
+ describe " when 7, 1 and 3 have been inserted in order", :deterministic => true do
attr_reader :inserted_nodes
def expected_node_heights
[1, 1, 2]
end
- it_should_behave_like "#next_node_height is deterministic"
+ include NextNodeHeightIsDeterministicSharedContext
before do
@inserted_nodes = []
4 spec/runtime/interval_skip_list/insert_spec.rb
View
@@ -1,6 +1,6 @@
require 'runtime/interval_skip_list/spec_helper'
-describe IntervalSkipList, " when #next_node_height returns 1, 3, 2, 3, 1 in order" do
+describe IntervalSkipList, " when #next_node_height returns 1, 3, 2, 3, 1 in order", :deterministic => true do
include IntervalSkipListSpecHelper
attr_reader :list, :node
@@ -8,7 +8,7 @@
@list = IntervalSkipList.new
end
- it_should_behave_like "#next_node_height is deterministic"
+ include NextNodeHeightIsDeterministicSharedContext
def expected_node_heights
[1, 3, 2, 3, 1]
38 spec/runtime/interval_skip_list/palindromic_fixture.rb
View
@@ -1,23 +1,35 @@
-describe "the palindromic fixture", :shared => true do
- attr_reader :list, :node
+module PalindromicFixtureSharedContext
+ extend RSpec::Core::SharedContext
include IntervalSkipListSpecHelper
- before do
+ attr_reader :list, :node
+
+ def construct_interval_skip_list
@list = IntervalSkipList.new
end
- it_should_behave_like "#next_node_height is deterministic"
def expected_node_heights
[3, 2, 1, 3, 1, 2, 3]
end
- before do
- list.insert(1..3, :a)
- list.insert(1..5, :b)
- list.insert(1..7, :c)
- list.insert(1..9, :d)
- list.insert(1..11, :e)
- list.insert(1..13, :f)
- list.insert(5..13, :g)
+ def populate_interval_skip_list
+ @list.insert(1..3, :a)
+ @list.insert(1..5, :b)
+ @list.insert(1..7, :c)
+ @list.insert(1..9, :d)
+ @list.insert(1..11, :e)
+ @list.insert(1..13, :f)
+ @list.insert(5..13, :g)
+ end
+
+ def make_it_determinisitic
+ extend NextNodeHeightIsDeterministicSharedContext # use the method without getting the filter
+ next_node_height_is_deterministic
+ end
+
+ before :each do
+ construct_interval_skip_list
+ make_it_determinisitic
+ populate_interval_skip_list
end
-end
+end
4 spec/runtime/interval_skip_list/palindromic_fixture_spec.rb
View
@@ -1,7 +1,7 @@
require 'runtime/interval_skip_list/spec_helper'
-describe "The palindromic fixture" do
- it_should_behave_like "the palindromic fixture"
+describe "The palindromic fixture", :palindromic => true do
+ include PalindromicFixtureSharedContext
describe " #nodes" do
describe "[0]" do
11 spec/runtime/interval_skip_list/spec_helper.rb
View
@@ -4,8 +4,15 @@ class IntervalSkipList
public :insert_node, :delete_node, :nodes, :head, :next_node_height
end
-describe "#next_node_height is deterministic", :shared => true do
- before do
+module NextNodeHeightIsDeterministicSharedContext
+ extend RSpec::Core::SharedContext
+
+ before :each do
+ next_node_height_is_deterministic
+ end
+
+ # @todo we call this in one place other than here. cleanup?
+ def next_node_height_is_deterministic
node_heights = expected_node_heights.dup
stub(list).next_node_height { node_heights.shift }
end
24 spec/spec_helper.rb
View
@@ -1,19 +1,15 @@
require 'rubygems'
require 'benchmark'
-require 'spec'
+require 'rspec'
require 'polyglot'
$LOAD_PATH.unshift File.expand_path('../../lib')
require 'treetop'
include Treetop
-Spec::Runner.configure do |config|
- config.mock_with :rr
-end
-
module Treetop
- class TreetopExampleGroup < Spec::Example::ExampleGroup
- class << self
+ module ExampleGroupInstanceMethods
+ module ClassMethods
attr_accessor :parser_class_under_test
def testing_expression(expression_under_test)
@@ -65,6 +61,11 @@ def parse(input, options = {})
def parse_multibyte(input, options = {})
require 'active_support/all'
+
+ if 'NONE' == $KCODE then $KCODE = 'UTF8' end
+ # rspec 1.3 used to do something similar (set it to 'u') that we need
+ # for activerecord multibyte wrapper to kick in (1.8 only? @todo)
+
parse(input.mb_chars, options)
end
@@ -95,12 +96,15 @@ def optionally_benchmark(&block)
yield
end
end
-
- Spec::Example::ExampleGroupFactory.register(:compiler, self)
- Spec::Example::ExampleGroupFactory.register(:runtime, self)
end
end
+RSpec.configure do |c|
+ c.mock_with :rr
+ c.extend Treetop::ExampleGroupInstanceMethods::ClassMethods
+ c.include Treetop::ExampleGroupInstanceMethods
+end
+
class Symbol
def to_proc
lambda do |x|
Something went wrong with that request. Please try again.