Permalink
Browse files

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

- also removed obsolete experimental cuke feature
  • Loading branch information...
1 parent 578d977 commit 0fad79c21eafa21e875a72f9a06d73d501d66dea @dchelimsky dchelimsky committed Dec 5, 2010
@@ -1,53 +0,0 @@
-Feature: shared context
-
- Common setup, teardown, helper methods, etc, can be shared across example
- groups using a SharedContext: a Ruby Module that extends RSpec::SharedContext
-
- Scenario: share a helper method
- Given a file named "example_spec.rb" with:
- """
- module Helpers
- extend RSpec::SharedContext
-
- def helper_method
- "text from the helper method"
- end
- end
-
- describe "something" do
- include Helpers
-
- it "does something" do
- helper_method.should match(/^text from/)
- end
- end
- """
- When I run "rspec example_spec.rb"
- Then the examples should all pass
-
- Scenario: share before and after hooks
- Given a file named "example_spec.rb" with:
- """
- module Shared
- extend RSpec::SharedContext
-
- before(:all) { puts "before all" }
- before(:each) { puts "before each" }
- after(:each) { puts "after each" }
- after(:all) { puts "after all" }
- end
-
- describe "something" do
- include Shared
- example { puts "example" }
- end
- """
- When I run "rspec example_spec.rb"
- And the output should contain:
- """
- before all
- before each
- example
- after each
- .after all
- """
@@ -0,0 +1,63 @@
+Feature: configure expectation framework
+
+ By default, RSpec is configured to include rspec-expectations for expressing
+ desired outcomes. You can also configure RSpec to use:
+
+ rspec/expectations (explicitly)
+ test/unit/assertions
+ rspec/expecations _and_ test/unit assertions
+
+ Scenario: configure rspec-expectations (explicitly)
+ Given a file named "example_spec.rb" with:
+ """
+ RSpec.configure do |config|
+ config.expect_with :rspec
+ end
+
+ describe 5 do
+ it "is greater than 4" do
+ 5.should be > 4
+ end
+ end
+ """
+ When I run "rspec example_spec.rb"
+ Then the output should contain "1 example, 0 failures"
+ And the exit status should be 0
+
+ Scenario: configure test/unit assertions
+ Given a file named "example_spec.rb" with:
+ """
+ RSpec.configure do |config|
+ config.expect_with :stdlib
+ end
+
+ describe 5 do
+ it "is greater than 4" do
+ assert 5 > 4, "expected 5 to be greater than 4"
+ end
+ end
+ """
+ When I run "rspec example_spec.rb"
+ Then the output should contain "1 example, 0 failures"
+ And the exit status should be 0
+
+ Scenario: configure rspec/expecations AND test/unit assertions
+ Given a file named "example_spec.rb" with:
+ """
+ RSpec.configure do |config|
+ config.expect_with :rspec, :stdlib
+ end
+
+ describe 5 do
+ it "is greater than 4" do
+ assert 5 > 4, "expected 5 to be greater than 4"
+ end
+
+ it "is less than 4" do
+ 5.should be < 6
+ end
+ end
+ """
+ When I run "rspec example_spec.rb"
+ Then the output should contain "2 examples, 0 failures"
+ And the exit status should be 0
@@ -236,36 +236,36 @@ Feature: around hooks
Scenario: multiple around hooks in the same scope
Given a file named "example_spec.rb" with:
- """
- describe "if there are multiple around hooks in the same scope" do
- around(:each) do |example|
- puts "first around hook before"
- example.run
- puts "first around hook after"
- end
+ """
+ describe "if there are multiple around hooks in the same scope" do
+ around(:each) do |example|
+ puts "first around hook before"
+ example.run
+ puts "first around hook after"
+ end
- around(:each) do |example|
- puts "second around hook before"
- example.run
- puts "second around hook after"
- end
+ around(:each) do |example|
+ puts "second around hook before"
+ example.run
+ puts "second around hook after"
+ end
- it "they should all be run" do
- puts "in the example"
- 1.should == 1
+ it "they should all be run" do
+ puts "in the example"
+ 1.should == 1
+ end
end
- end
- """
+ """
When I run "rspec example_spec.rb"
Then the output should contain "1 example, 0 failure"
And the output should contain:
- """
- first around hook before
- second around hook before
- in the example
- second around hook after
- first around hook after
- """
+ """
+ first around hook before
+ second around hook before
+ in the example
+ second around hook after
+ first around hook after
+ """
Scenario: around hooks in multiple scopes
Given a file named "example_spec.rb" with:
@@ -26,7 +26,6 @@ def self.add_setting(name, opts={})
add_setting :profile_examples
add_setting :fail_fast, :default => false
add_setting :run_all_when_everything_filtered
- add_setting :expectation_framework, :default => :rspec
add_setting :filter
add_setting :exclusion_filter
add_setting :filename_pattern, :default => '**/*_spec.rb'
@@ -168,31 +167,41 @@ def mock_framework=(framework)
end
end
- # Returns the configured expectation framework adapter module
- def expectation_framework
- settings[:expectation_framework] ||= begin
+ # Returns the configured expectation framework adapter module(s)
+ def expectation_frameworks
+ settings[:expectation_frameworks] ||= begin
require 'rspec/core/expecting/with_rspec'
- RSpec::Core::ExpectationFrameworkAdapter
+ [RSpec::Core::ExpectationFrameworkAdapter]
end
end
- # Delegates to expectation_framework=(framework)
- def expect_with(framework)
- self.expectation_framework = framework
+ # Delegates to expect_with=([framework])
+ def expectation_framework=(framework)
+ expect_with([framework])
end
- # Sets the expectation framework module.
+ # Sets the expectation framework module(s).
#
- # +framework+ can be a Symbol or a Module.
+ # +frameworks+ can be :rspec, :stdlib, or both
#
- # Given :rspec, configures rspec-expectations.
- def expectation_framework=(framework)
- case framework
- when :rspec
- require 'rspec/core/expecting/with_rspec'
- settings[:expectation_framework] = RSpec::Core::ExpectationFrameworkAdapter
- else
- raise ArgumentError, "#{expectation_framework.inspect} is not supported"
+ # Given :rspec, configures rspec/expectations.
+ # Given :stdlib, configures test/unit/assertions
+ # Given both, configures both
+ def expect_with(*frameworks)
+ settings[:expectation_frameworks] = []
+ frameworks.each do |framework|
+ case framework
+ when Symbol
+ case framework
+ when :rspec
+ require 'rspec/core/expecting/with_rspec'
+ when :stdlib
+ require 'rspec/core/expecting/with_stdlib'
+ else
+ raise ArgumentError, "#{framework.inspect} is not supported"
+ end
+ settings[:expectation_frameworks] << RSpec::Core::ExpectationFrameworkAdapter
+ end
end
end
@@ -370,7 +379,9 @@ def configure_mock_framework
end
def configure_expectation_framework
- RSpec::Core::ExampleGroup.send(:include, expectation_framework)
+ expectation_frameworks.each do |framework|
+ RSpec::Core::ExampleGroup.send(:include, framework)
+ end
end
def load_spec_files
@@ -0,0 +1,9 @@
+require 'test/unit/assertions'
+
+module RSpec
+ module Core
+ module ExpectationFrameworkAdapter
+ include Test::Unit::Assertions
+ end
+ end
+end
@@ -71,30 +71,30 @@ module RSpec::Core
describe "#expectation_framework" do
it "defaults to :rspec" do
config.should_receive(:require).with('rspec/core/expecting/with_rspec')
- config.expectation_framework
+ config.expectation_frameworks
end
end
describe "#expectation_framework=" do
- [:rspec].each do |framework|
+ it "delegates to expect_with=" do
+ config.should_receive(:expect_with).with([:rspec])
+ config.expectation_framework = :rspec
+ end
+ end
+
+ describe "#expect_with" do
+ [:rspec, :stdlib].each do |framework|
context "with #{framework}" do
it "requires the adapter for #{framework.inspect}" do
config.should_receive(:require).with("rspec/core/expecting/with_#{framework}")
- config.expectation_framework = framework
+ config.expect_with framework
end
end
end
- end
-
- describe "#expect_with" do
- it "delegates to expectation_framework=" do
- config.should_receive(:expectation_framework=).with(:rspec)
- config.expect_with :rspec
- end
it "raises ArgumentError if framework is not supported" do
expect do
- config.expectation_framework = :not_supported
+ config.expect_with :not_supported
end.to raise_error(ArgumentError)
end
end

0 comments on commit 0fad79c

Please sign in to comment.