Skip to content
This repository
Browse code

add Upgrade information

  • Loading branch information...
commit 4828e77ab16f3cefa4322e20819541c66bbff954 1 parent a7a8b4f
David Chelimsky authored March 03, 2010

Showing 1 changed file with 94 additions and 0 deletions. Show diff stats Hide diff stats

  1. 94  Upgrade.markdown
94  Upgrade.markdown
Source Rendered
... ...
@@ -0,0 +1,94 @@
  1
+# Upgrade to rspec-core-2.0
  2
+
  3
+## What's changed
  4
+
  5
+### Rspec namespace
  6
+
  7
+The root namespace is now `Rspec` instead of `Spec`, and the root directory
  8
+under `lib` is `rspec` instead of `spec`.
  9
+
  10
+### Configuration
  11
+
  12
+Typically in `spec/spec_helper.rb`, configuration is now done like this:
  13
+
  14
+    Rspec.configure do |c|
  15
+      # ....
  16
+    end
  17
+
  18
+### rspec commmand
  19
+
  20
+The command to run specs is now `rspec` instead of `spec`.
  21
+
  22
+    rspec ./spec
  23
+
  24
+## What's new
  25
+
  26
+### Runner
  27
+
  28
+The new runner for rspec-2 comes from Micronaut.
  29
+
  30
+### Metadata!
  31
+
  32
+In rspec-2, every example and example group comes with metadata information
  33
+like the file and line number on which it was declared, the arguments passed to
  34
+`describe` and `it`, etc.  This metadata can be appended to through a hash
  35
+argument passed to `describe` or `it`, allowing us to pre and post-process
  36
+each example in a variety of ways.
  37
+
  38
+The most obvious use is for filtering the run. For example:
  39
+
  40
+    # in spec/spec_helper.rb
  41
+    Rspec.configure do |c|
  42
+      c.filter_run :focus => true
  43
+    end
  44
+
  45
+    # in any spec file
  46
+    describe "something" do
  47
+      it "does something", :focus => true do
  48
+        # ....
  49
+      end
  50
+    end
  51
+
  52
+When you run the `rspec` command, rspec will run only the examples that have
  53
+`:focus => true` in the hash. 
  54
+
  55
+You can also add `run_all_when_everything_filtered` to the config:
  56
+
  57
+    Rspec.configure do |c|
  58
+      c.filter_run :focus => true
  59
+      c.run_all_when_everything_filtered = true
  60
+    end
  61
+
  62
+Now if there are no examples tagged with `:focus => true`, all examples
  63
+will be run. This makes it really easy to focus on one example for a
  64
+while, but then go back to running all of the examples by removing that
  65
+argument from `it`. Works with `describe` too, in which case it runs
  66
+all of the examples in that group.
  67
+
  68
+The configuration will accept a lambda, which provides a lot of flexibility
  69
+in filtering examples. Say, for example, you have a spec for functionality that
  70
+behaves slightly differently in Ruby 1.8 and Ruby 1.9. We have that in
  71
+rspec-core, and here's how we're getting the right stuff to run under the
  72
+right version:
  73
+
  74
+    # in spec/spec_helper.rb
  75
+    Rspec.configure do |c|
  76
+      c.exclusion_filter = { :ruby => lambda {|version|
  77
+        !(RUBY_VERSION.to_s =~ /^#{version.to_s}/)
  78
+      }}
  79
+    end
  80
+
  81
+    # in any spec file
  82
+    describe "something" do
  83
+      it "does something", :ruby => 1.8 do
  84
+        # ....
  85
+      end
  86
+
  87
+      it "does something", :ruby => 1.9 do
  88
+        # ....
  89
+      end
  90
+    end
  91
+
  92
+In this case, we're using `exclusion_filter` instead of `filter_run` or
  93
+`filter`, which indicate _inclusion_ filters. So each of those examples is
  94
+excluded if we're _not_ running the version of Ruby they work with.

0 notes on commit 4828e77

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