Skip to content

Commit

Permalink
Simplify how the expect_with configuration works.
Browse files Browse the repository at this point in the history
- There's no need to include RSpec::Matchers or Test::Unit::Assertions into an adapter module when we can just include them directly.
- It makes it possible to interrogate @expectation_frameworks to see what was already configured and included.  Before, @expectation_frameworks contained [RSpec::Core::ExpectationFrameworkAdapter], regardless of what was configured.
  • Loading branch information
myronmarston committed Nov 3, 2011
1 parent cb975e0 commit 511f4ba
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
12 changes: 8 additions & 4 deletions lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +223,22 @@ def expectation_framework=(framework)
def expect_with(*frameworks)
assert_no_example_groups_defined(:expect_with)
@expectation_frameworks.clear
frameworks.each do |framework|

modules = frameworks.map do |framework|
case framework
when :rspec
require 'rspec/core/expecting/with_rspec'
require 'rspec/expectations'
self.expecting_with_rspec = true
::RSpec::Matchers
when :stdlib
require 'rspec/core/expecting/with_stdlib'
require 'test/unit/assertions'
::Test::Unit::Assertions
else
raise ArgumentError, "#{framework.inspect} is not supported"
end
@expectation_frameworks << RSpec::Core::ExpectationFrameworkAdapter
end

@expectation_frameworks.push(*modules)
end

def full_backtrace=(true_or_false)
Expand Down
9 changes: 0 additions & 9 deletions lib/rspec/core/expecting/with_rspec.rb

This file was deleted.

9 changes: 0 additions & 9 deletions lib/rspec/core/expecting/with_stdlib.rb

This file was deleted.

14 changes: 10 additions & 4 deletions spec/rspec/core/configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'spec_helper'
require 'tmpdir'

# so the stdlib module is available...
module Test; module Unit; module Assertions; end; end; end

module RSpec::Core

describe Configuration do
Expand Down Expand Up @@ -91,7 +94,7 @@ module RSpec::Core

describe "#expectation_framework" do
it "defaults to :rspec" do
config.should_receive(:require).with('rspec/core/expecting/with_rspec')
config.should_receive(:require).with('rspec/expectations')
config.expectation_frameworks
end
end
Expand All @@ -104,10 +107,13 @@ module RSpec::Core
end

describe "#expect_with" do
[:rspec, :stdlib].each do |framework|
[
[:rspec, 'rspec/expectations'],
[:stdlib, 'test/unit/assertions']
].each do |(framework, required_file)|
context "with #{framework}" do
it "requires the adapter for #{framework.inspect}" do
config.should_receive(:require).with("rspec/core/expecting/with_#{framework}")
it "requires #{required_file}" do
config.should_receive(:require).with(required_file)
config.expect_with framework
end
end
Expand Down

0 comments on commit 511f4ba

Please sign in to comment.