Skip to content
This repository
Browse code

Support using rspec/expecations, test/unit/assertions, or both.

- also removed obsolete experimental cuke feature
  • Loading branch information...
commit 0fad79c21eafa21e875a72f9a06d73d501d66dea 1 parent 578d977
David Chelimsky dchelimsky authored
53 features/example_groups/shared_context.feature
... ... @@ -1,53 +0,0 @@
1   -Feature: shared context
2   -
3   - Common setup, teardown, helper methods, etc, can be shared across example
4   - groups using a SharedContext: a Ruby Module that extends RSpec::SharedContext
5   -
6   - Scenario: share a helper method
7   - Given a file named "example_spec.rb" with:
8   - """
9   - module Helpers
10   - extend RSpec::SharedContext
11   -
12   - def helper_method
13   - "text from the helper method"
14   - end
15   - end
16   -
17   - describe "something" do
18   - include Helpers
19   -
20   - it "does something" do
21   - helper_method.should match(/^text from/)
22   - end
23   - end
24   - """
25   - When I run "rspec example_spec.rb"
26   - Then the examples should all pass
27   -
28   - Scenario: share before and after hooks
29   - Given a file named "example_spec.rb" with:
30   - """
31   - module Shared
32   - extend RSpec::SharedContext
33   -
34   - before(:all) { puts "before all" }
35   - before(:each) { puts "before each" }
36   - after(:each) { puts "after each" }
37   - after(:all) { puts "after all" }
38   - end
39   -
40   - describe "something" do
41   - include Shared
42   - example { puts "example" }
43   - end
44   - """
45   - When I run "rspec example_spec.rb"
46   - And the output should contain:
47   - """
48   - before all
49   - before each
50   - example
51   - after each
52   - .after all
53   - """
63 features/expectation_framework_integration/configure_expectation_framework.feature
... ... @@ -0,0 +1,63 @@
  1 +Feature: configure expectation framework
  2 +
  3 + By default, RSpec is configured to include rspec-expectations for expressing
  4 + desired outcomes. You can also configure RSpec to use:
  5 +
  6 + rspec/expectations (explicitly)
  7 + test/unit/assertions
  8 + rspec/expecations _and_ test/unit assertions
  9 +
  10 + Scenario: configure rspec-expectations (explicitly)
  11 + Given a file named "example_spec.rb" with:
  12 + """
  13 + RSpec.configure do |config|
  14 + config.expect_with :rspec
  15 + end
  16 +
  17 + describe 5 do
  18 + it "is greater than 4" do
  19 + 5.should be > 4
  20 + end
  21 + end
  22 + """
  23 + When I run "rspec example_spec.rb"
  24 + Then the output should contain "1 example, 0 failures"
  25 + And the exit status should be 0
  26 +
  27 + Scenario: configure test/unit assertions
  28 + Given a file named "example_spec.rb" with:
  29 + """
  30 + RSpec.configure do |config|
  31 + config.expect_with :stdlib
  32 + end
  33 +
  34 + describe 5 do
  35 + it "is greater than 4" do
  36 + assert 5 > 4, "expected 5 to be greater than 4"
  37 + end
  38 + end
  39 + """
  40 + When I run "rspec example_spec.rb"
  41 + Then the output should contain "1 example, 0 failures"
  42 + And the exit status should be 0
  43 +
  44 + Scenario: configure rspec/expecations AND test/unit assertions
  45 + Given a file named "example_spec.rb" with:
  46 + """
  47 + RSpec.configure do |config|
  48 + config.expect_with :rspec, :stdlib
  49 + end
  50 +
  51 + describe 5 do
  52 + it "is greater than 4" do
  53 + assert 5 > 4, "expected 5 to be greater than 4"
  54 + end
  55 +
  56 + it "is less than 4" do
  57 + 5.should be < 6
  58 + end
  59 + end
  60 + """
  61 + When I run "rspec example_spec.rb"
  62 + Then the output should contain "2 examples, 0 failures"
  63 + And the exit status should be 0
48 features/hooks/around_hooks.feature
@@ -236,36 +236,36 @@ Feature: around hooks
236 236
237 237 Scenario: multiple around hooks in the same scope
238 238 Given a file named "example_spec.rb" with:
239   - """
240   - describe "if there are multiple around hooks in the same scope" do
241   - around(:each) do |example|
242   - puts "first around hook before"
243   - example.run
244   - puts "first around hook after"
245   - end
  239 + """
  240 + describe "if there are multiple around hooks in the same scope" do
  241 + around(:each) do |example|
  242 + puts "first around hook before"
  243 + example.run
  244 + puts "first around hook after"
  245 + end
246 246
247   - around(:each) do |example|
248   - puts "second around hook before"
249   - example.run
250   - puts "second around hook after"
251   - end
  247 + around(:each) do |example|
  248 + puts "second around hook before"
  249 + example.run
  250 + puts "second around hook after"
  251 + end
252 252
253   - it "they should all be run" do
254   - puts "in the example"
255   - 1.should == 1
  253 + it "they should all be run" do
  254 + puts "in the example"
  255 + 1.should == 1
  256 + end
256 257 end
257   - end
258   - """
  258 + """
259 259 When I run "rspec example_spec.rb"
260 260 Then the output should contain "1 example, 0 failure"
261 261 And the output should contain:
262   - """
263   - first around hook before
264   - second around hook before
265   - in the example
266   - second around hook after
267   - first around hook after
268   - """
  262 + """
  263 + first around hook before
  264 + second around hook before
  265 + in the example
  266 + second around hook after
  267 + first around hook after
  268 + """
269 269
270 270 Scenario: around hooks in multiple scopes
271 271 Given a file named "example_spec.rb" with:
49 lib/rspec/core/configuration.rb
@@ -26,7 +26,6 @@ def self.add_setting(name, opts={})
26 26 add_setting :profile_examples
27 27 add_setting :fail_fast, :default => false
28 28 add_setting :run_all_when_everything_filtered
29   - add_setting :expectation_framework, :default => :rspec
30 29 add_setting :filter
31 30 add_setting :exclusion_filter
32 31 add_setting :filename_pattern, :default => '**/*_spec.rb'
@@ -168,31 +167,41 @@ def mock_framework=(framework)
168 167 end
169 168 end
170 169
171   - # Returns the configured expectation framework adapter module
172   - def expectation_framework
173   - settings[:expectation_framework] ||= begin
  170 + # Returns the configured expectation framework adapter module(s)
  171 + def expectation_frameworks
  172 + settings[:expectation_frameworks] ||= begin
174 173 require 'rspec/core/expecting/with_rspec'
175   - RSpec::Core::ExpectationFrameworkAdapter
  174 + [RSpec::Core::ExpectationFrameworkAdapter]
176 175 end
177 176 end
178 177
179   - # Delegates to expectation_framework=(framework)
180   - def expect_with(framework)
181   - self.expectation_framework = framework
  178 + # Delegates to expect_with=([framework])
  179 + def expectation_framework=(framework)
  180 + expect_with([framework])
182 181 end
183 182
184   - # Sets the expectation framework module.
  183 + # Sets the expectation framework module(s).
185 184 #
186   - # +framework+ can be a Symbol or a Module.
  185 + # +frameworks+ can be :rspec, :stdlib, or both
187 186 #
188   - # Given :rspec, configures rspec-expectations.
189   - def expectation_framework=(framework)
190   - case framework
191   - when :rspec
192   - require 'rspec/core/expecting/with_rspec'
193   - settings[:expectation_framework] = RSpec::Core::ExpectationFrameworkAdapter
194   - else
195   - raise ArgumentError, "#{expectation_framework.inspect} is not supported"
  187 + # Given :rspec, configures rspec/expectations.
  188 + # Given :stdlib, configures test/unit/assertions
  189 + # Given both, configures both
  190 + def expect_with(*frameworks)
  191 + settings[:expectation_frameworks] = []
  192 + frameworks.each do |framework|
  193 + case framework
  194 + when Symbol
  195 + case framework
  196 + when :rspec
  197 + require 'rspec/core/expecting/with_rspec'
  198 + when :stdlib
  199 + require 'rspec/core/expecting/with_stdlib'
  200 + else
  201 + raise ArgumentError, "#{framework.inspect} is not supported"
  202 + end
  203 + settings[:expectation_frameworks] << RSpec::Core::ExpectationFrameworkAdapter
  204 + end
196 205 end
197 206 end
198 207
@@ -370,7 +379,9 @@ def configure_mock_framework
370 379 end
371 380
372 381 def configure_expectation_framework
373   - RSpec::Core::ExampleGroup.send(:include, expectation_framework)
  382 + expectation_frameworks.each do |framework|
  383 + RSpec::Core::ExampleGroup.send(:include, framework)
  384 + end
374 385 end
375 386
376 387 def load_spec_files
9 lib/rspec/core/expecting/with_stdlib.rb
... ... @@ -0,0 +1,9 @@
  1 +require 'test/unit/assertions'
  2 +
  3 +module RSpec
  4 + module Core
  5 + module ExpectationFrameworkAdapter
  6 + include Test::Unit::Assertions
  7 + end
  8 + end
  9 +end
22 spec/rspec/core/configuration_spec.rb
@@ -71,30 +71,30 @@ module RSpec::Core
71 71 describe "#expectation_framework" do
72 72 it "defaults to :rspec" do
73 73 config.should_receive(:require).with('rspec/core/expecting/with_rspec')
74   - config.expectation_framework
  74 + config.expectation_frameworks
75 75 end
76 76 end
77 77
78 78 describe "#expectation_framework=" do
79   - [:rspec].each do |framework|
  79 + it "delegates to expect_with=" do
  80 + config.should_receive(:expect_with).with([:rspec])
  81 + config.expectation_framework = :rspec
  82 + end
  83 + end
  84 +
  85 + describe "#expect_with" do
  86 + [:rspec, :stdlib].each do |framework|
80 87 context "with #{framework}" do
81 88 it "requires the adapter for #{framework.inspect}" do
82 89 config.should_receive(:require).with("rspec/core/expecting/with_#{framework}")
83   - config.expectation_framework = framework
  90 + config.expect_with framework
84 91 end
85 92 end
86 93 end
87   - end
88   -
89   - describe "#expect_with" do
90   - it "delegates to expectation_framework=" do
91   - config.should_receive(:expectation_framework=).with(:rspec)
92   - config.expect_with :rspec
93   - end
94 94
95 95 it "raises ArgumentError if framework is not supported" do
96 96 expect do
97   - config.expectation_framework = :not_supported
  97 + config.expect_with :not_supported
98 98 end.to raise_error(ArgumentError)
99 99 end
100 100 end

0 comments on commit 0fad79c

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