Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: rspec/rspec-core
base: v2.2.0
...
head fork: rspec/rspec-core
compare: events
Checking mergeability… Don't worry, you can still create the pull request.
  • 14 commits
  • 18 files changed
  • 3 commit comments
  • 1 contributor
View
2  features/configuration/options_file.feature
@@ -57,7 +57,7 @@ Feature: spec/spec.opts
describe "formatter" do
context "when set with RSpec.configure and in spec.opts" do
it "takes the value set in spec.opts" do
- RSpec.configuration.formatter.should be_an(RSpec::Core::Formatters::DocumentationFormatter)
+ RSpec.configuration.formatter.subscribers.first.should be_an(RSpec::Core::Formatters::DocumentationFormatter)
end
end
end
View
72 lib/rspec/core.rb
@@ -1,3 +1,36 @@
+module RSpec
+ class << self
+ def subscriptions
+ @subscriptions ||= Hash.new {|h,k| h[k] = []}
+ end
+
+ # Supported events:
+ # example_group_started
+ # example_started
+ # example_initialized
+ # example_executed
+ # example_finished
+ def subscribe(event, &callback)
+ subscriptions[event] << callback
+ end
+
+ def publish(event, *args)
+ subscriptions[event].each {|callback| callback.call(*args)}
+ end
+ def world
+ @world ||= RSpec::Core::World.new
+ end
+
+ def configuration
+ @configuration ||= RSpec::Core::Configuration.new
+ end
+
+ def configure
+ yield configuration if block_given?
+ end
+ end
+end
+
require 'rspec/core/kernel_extensions'
require 'rspec/core/object_extensions'
require 'rspec/core/load_path'
@@ -12,6 +45,7 @@
require 'rspec/core/around_proxy'
require 'rspec/core/world'
+require 'rspec/core/notifier'
require 'rspec/core/configuration'
require 'rspec/core/option_parser'
require 'rspec/core/configuration_options'
@@ -23,44 +57,6 @@
require 'rspec/core/example_group'
require 'rspec/core/version'
require 'rspec/core/errors'
-
-module RSpec
- module Core
-
- def self.install_directory
- @install_directory ||= File.expand_path(File.dirname(__FILE__))
- end
-
- def self.configuration
- RSpec.deprecate('RSpec::Core.configuration', 'RSpec.configuration', '2.0.0')
- RSpec.configuration
- end
-
- def self.configure
- RSpec.deprecate('RSpec::Core.configure', 'RSpec.configure', '2.0.0')
- yield RSpec.configuration if block_given?
- end
-
- def self.world
- RSpec.deprecate('RSpec::Core.world', 'RSpec.world', '2.0.0')
- RSpec.world
- end
-
- end
-
- def self.world
- @world ||= RSpec::Core::World.new
- end
-
- def self.configuration
- @configuration ||= RSpec::Core::Configuration.new
- end
-
- def self.configure
- yield configuration if block_given?
- end
-end
-
require 'rspec/core/backward_compatibility'
# TODO - make this configurable with default 'on'
View
6 lib/rspec/core/backward_compatibility.rb
@@ -1,11 +1,5 @@
module RSpec
module Core
- class Configuration
- def mock_with(use_me_to_mock)
- self.mock_framework = use_me_to_mock
- end
- end
-
module ConstMissing
def const_missing(name)
case name
View
17 lib/rspec/core/command_line.rb
@@ -18,15 +18,18 @@ def run(err, out)
configuration.output_stream = out
world.announce_inclusion_filter
- configuration.reporter.report(example_count) do |reporter|
- begin
- configuration.run_hook(:before, :suite)
- example_groups.run_examples(reporter)
- ensure
- configuration.run_hook(:after, :suite)
- end
+ reporter = configuration.reporter
+ reporter.start(example_count)
+
+ begin
+ configuration.run_hook(:before, :suite)
+ example_groups.run_examples(reporter)
+ ensure
+ configuration.run_hook(:after, :suite)
end
+ reporter.stop
+
example_groups.success?
end
View
11 lib/rspec/core/configuration.rb
@@ -40,7 +40,7 @@ def self.add_setting(name, opts={})
/bin\/spec/,
/lib\/rspec\/(core|expectations|matchers|mocks)/
]
-
+
# :call-seq:
# add_setting(:name)
# add_setting(:name, :default => "default_value")
@@ -99,6 +99,10 @@ def cleaned_from_backtrace?(line)
backtrace_clean_patterns.any? { |regex| line =~ regex }
end
+ def mock_with(mock_framework)
+ self.mock_framework = mock_framework
+ end
+
def require_mock_framework_adapter
require case mock_framework.to_s
when /rspec/i
@@ -189,9 +193,9 @@ def formatter=(formatter_to_use)
def string_const?(str)
str.is_a?(String) && /\A[A-Z][a-zA-Z0-9_:]*\z/ =~ str
end
-
+
def formatter
- @formatter ||= formatter_class.new(output)
+ @formatter ||= RSpec::Core::Notifier.new(formatter_class.new(output))
end
alias_method :reporter, :formatter
@@ -243,7 +247,6 @@ def find_modules(group)
def configure_mock_framework
require_mock_framework_adapter
- RSpec::Core::ExampleGroup.send(:include, RSpec::Core::MockFrameworkAdapter)
end
def require_files_to_run
View
22 lib/rspec/core/example.rb
@@ -1,8 +1,15 @@
module RSpec
module Core
class Example
+ RSpec.subscribe(:example_initialized) {|e| e.example.in_block = true}
+ RSpec.subscribe(:example_executed) {|e| e.example.in_block = false}
attr_reader :metadata, :example_block, :options
+ attr_accessor :in_block
+
+ def in_block?
+ !!in_block
+ end
def self.delegate_to_metadata(*keys)
keys.each do |key|
@@ -24,14 +31,13 @@ def example_group
@example_group_class
end
- def in_block?
- @in_block
+ def specifies_attribute?
+ in_block && metadata[:attribute_of_subject]
end
alias_method :behaviour, :example_group
def run(example_group_instance, reporter)
- @in_block = false
@example_group_instance = example_group_instance
@example_group_instance.example = self
@@ -40,9 +46,10 @@ def run(example_group_instance, reporter)
exception = nil
begin
+ reporter.example_started(@example_group_instance)
run_before_each
+ reporter.example_initialized(@example_group_instance)
pending_declared_in_example = catch(:pending_declared_in_example) do
- @in_block = true
if @example_group_class.hooks[:around][:each].empty?
@example_group_instance.instance_eval(&example_block) unless pending
else
@@ -53,7 +60,7 @@ def run(example_group_instance, reporter)
rescue Exception => e
exception = e
ensure
- @in_block = false
+ reporter.example_executed(@example_group_instance)
assign_auto_description
end
@@ -105,15 +112,11 @@ def run_finished(reporter, status, results={})
end
def run_before_each
- @example_group_instance._setup_mocks if @example_group_instance.respond_to?(:_setup_mocks)
@example_group_class.eval_before_eachs(@example_group_instance)
end
def run_after_each
@example_group_class.eval_after_eachs(@example_group_instance)
- @example_group_instance._verify_mocks if @example_group_instance.respond_to?(:_verify_mocks)
- ensure
- @example_group_instance._teardown_mocks if @example_group_instance.respond_to?(:_teardown_mocks)
end
def assign_auto_description
@@ -126,7 +129,6 @@ def assign_auto_description
def record_results(results={})
execution_result.update(results)
end
-
end
end
end
View
1  lib/rspec/core/example_group.rb
@@ -58,6 +58,7 @@ class << self
alias_example_to :specify
alias_example_to :focused, :focused => true
alias_example_to :pending, :pending => true
+ alias_example_to :xit, :pending => true
def self.it_should_behave_like(*names)
names.each do |name|
View
30 lib/rspec/core/formatters/base_formatter.rb
@@ -22,17 +22,12 @@ def failed_examples
@failed_examples ||= ::RSpec.world.find(examples, :execution_result => { :status => 'failed' })
end
- def report(count)
- sync_output do
- start(count)
- begin
- yield self
- ensure
- stop
- dump(@duration)
- close
- end
- end
+ def start_sync_output
+ @old_sync, output.sync = output.sync, true if output_supports_sync
+ end
+
+ def restore_sync_status
+ output.sync = @old_sync if output_supports_sync
end
# This method is invoked before any examples are run, right after
@@ -42,12 +37,16 @@ def report(count)
# This method will only be invoked once, and the next one to be invoked
# is #add_example_group
def start(example_count)
+ start_sync_output
@start = Time.now
@example_count = example_count
end
def stop
@duration = Time.now - @start
+ dump(@duration)
+ close
+ restore_sync_status
end
def example_finished(example)
@@ -129,15 +128,6 @@ def read_failed_line(exception, example)
end
end
- def sync_output
- begin
- old_sync, output.sync = output.sync, true if output_supports_sync
- yield
- ensure
- output.sync = old_sync if output_supports_sync
- end
- end
-
def output_supports_sync
output.respond_to?(:sync=)
end
View
11 lib/rspec/core/mocking/with_absolutely_nothing.rb
@@ -1,11 +0,0 @@
-module RSpec
- module Core
- module MockFrameworkAdapter
-
- def _setup_mocks; end
- def _verify_mocks; end
- def _teardown_mocks; end
-
- end
- end
-end
View
23 lib/rspec/core/mocking/with_flexmock.rb
@@ -5,21 +5,14 @@
require 'flexmock/rspec'
-module RSpec
- module Core
- module MockFrameworkAdapter
-
- include FlexMock::MockContainer
- def setup_mocks_for_rspec
- # No setup required
- end
- def verify_mocks_for_rspec
- flexmock_verify
- end
- def teardown_mocks_for_rspec
- flexmock_close
- end
+RSpec.subscribe(:example_started) do |example|
+ example.extend FlexMock::MockContainer
+end
- end
+RSpec.subscribe(:example_executed) do |example|
+ begin
+ example.flexmock_verify
+ ensure
+ example.flexmock_close
end
end
View
29 lib/rspec/core/mocking/with_mocha.rb
@@ -1,21 +1,20 @@
require 'mocha/standalone'
require 'mocha/object'
-module RSpec
- module Core
- module MockFrameworkAdapter
-
- # Mocha::Standalone was deprecated as of Mocha 0.9.7.
- begin
- include Mocha::API
- rescue NameError
- include Mocha::Standalone
- end
-
- alias :_setup_mocks :mocha_setup
- alias :_verify_mocks :mocha_verify
- alias :_teardown_mocks :mocha_teardown
+RSpec.subscribe(:example_started) do |example|
+ # Mocha::Standalone was deprecated as of Mocha 0.9.7.
+ begin
+ example.extend Mocha::API
+ rescue NameError
+ example.extend Mocha::Standalone
+ end
+ example.mocha_setup
+end
- end
+RSpec.subscribe(:example_executed) do |example|
+ begin
+ example.mocha_verify
+ ensure
+ example.mocha_teardown
end
end
View
27 lib/rspec/core/mocking/with_rr.rb
@@ -2,24 +2,15 @@
RSpec.configuration.backtrace_clean_patterns.push(RR::Errors::BACKTRACE_IDENTIFIER)
-module RSpec
- module Core
- module MockFrameworkAdapter
-
- include RR::Extensions::InstanceMethods
-
- def _setup_mocks
- RR::Space.instance.reset
- end
-
- def _verify_mocks
- RR::Space.instance.verify_doubles
- end
-
- def _teardown_mocks
- RR::Space.instance.reset
- end
+RSpec.subscribe(:example_started) do |example|
+ example.extend RR::Extensions::InstanceMethods
+ RR::Space.instance.reset
+end
- end
+RSpec.subscribe(:example_executed) do |example|
+ begin
+ RR::Space.instance.verify_doubles
+ ensure
+ RR::Space.instance.reset
end
end
View
23 lib/rspec/core/mocking/with_rspec.rb
@@ -1,21 +1,16 @@
require 'rspec/mocks/framework'
require 'rspec/mocks/extensions'
-module RSpec
- module Core
- module MockFrameworkAdapter
+$rspec_mocks ||= RSpec::Mocks::Space.new
- include RSpec::Mocks::ExampleMethods
- def _setup_mocks
- $rspec_mocks ||= RSpec::Mocks::Space.new
- end
- def _verify_mocks
- $rspec_mocks.verify_all
- end
- def _teardown_mocks
- $rspec_mocks.reset_all
- end
+RSpec.subscribe(:example_started) do |example|
+ example.extend RSpec::Mocks::ExampleMethods
+end
- end
+RSpec.subscribe(:example_executed) do |example|
+ begin
+ $rspec_mocks.verify_all
+ ensure
+ $rspec_mocks.reset_all
end
end
View
18 lib/rspec/core/notifier.rb
@@ -0,0 +1,18 @@
+module RSpec::Core
+ class Notifier
+ def initialize(*subscribers)
+ self.subscribers.push(*subscribers)
+ end
+
+ def subscribers
+ @subscribers ||= []
+ end
+
+ def method_missing(method, *args, &block)
+ subscribers.each do |s|
+ RSpec.publish(method, *args)
+ s.send(method, *args, &block) if s.respond_to?(method)
+ end
+ end
+ end
+end
View
3  lib/rspec/core/subject.rb
@@ -84,8 +84,7 @@ def attribute_of_subject
end
def using_attribute?
- example.in_block? &&
- example.metadata[:attribute_of_subject]
+ example.specifies_attribute?
end
end
View
8 rspec-core.gemspec
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Chad Humphries", "David Chelimsky"]
- s.date = %q{2010-06-15}
+ s.date = %q{2010-06-19}
s.description = %q{RSpec runner and example group classes}
s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
s.executables = ["rspec", "spec"]
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
"bin/spec",
"cucumber.yml",
"features/command_line/example_name_option.feature",
+ "features/command_line/exit_status.feature",
"features/command_line/line_number_appended_to_path.feature",
"features/command_line/line_number_option.feature",
"features/configuration/custom_settings.feature",
@@ -95,6 +96,7 @@ Gem::Specification.new do |s|
"script/console",
"spec/autotest/failed_results_re_spec.rb",
"spec/autotest/rspec_spec.rb",
+ "spec/rspec/core/command_line_spec.rb",
"spec/rspec/core/configuration_options_spec.rb",
"spec/rspec/core/configuration_spec.rb",
"spec/rspec/core/deprecations_spec.rb",
@@ -138,7 +140,7 @@ Gem::Specification.new do |s|
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{rspec}
- s.rubygems_version = %q{1.3.6}
+ s.rubygems_version = %q{1.3.7}
s.summary = %q{rspec-core-2.0.0.beta.12}
s.test_files = [
"spec/autotest/failed_results_re_spec.rb",
@@ -181,7 +183,7 @@ Gem::Specification.new do |s|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_development_dependency(%q<rspec-expectations>, [">= 2.0.0.beta.12"])
s.add_development_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.12"])
s.add_development_dependency(%q<cucumber>, [">= 0.5.3"])
View
8 spec/rspec/core/configuration_spec.rb
@@ -235,21 +235,21 @@ def that_thing
it "sets formatter_to_use based on name" do
config.formatter = :documentation
- config.formatter.should be_an_instance_of(Formatters::DocumentationFormatter)
+ config.formatter.subscribers.first.should be_an_instance_of(Formatters::DocumentationFormatter)
config.formatter = 'documentation'
- config.formatter.should be_an_instance_of(Formatters::DocumentationFormatter)
+ config.formatter.subscribers.first.should be_an_instance_of(Formatters::DocumentationFormatter)
end
it "sets a formatter based on its class" do
formatter_class = Class.new(Formatters::BaseTextFormatter)
config.formatter = formatter_class
- config.formatter.should be_an_instance_of(formatter_class)
+ config.formatter.subscribers.first.should be_an_instance_of(formatter_class)
end
it "sets a formatter based on its class name" do
Object.const_set("CustomFormatter",Class.new(Formatters::BaseFormatter))
config.formatter = "CustomFormatter"
- config.formatter.should be_an_instance_of(CustomFormatter)
+ config.formatter.subscribers.first.should be_an_instance_of(CustomFormatter)
end
it "raises ArgumentError if formatter is unknown" do
View
4 spec/rspec/core/formatters/base_text_formatter_spec.rb
@@ -1,4 +1,5 @@
require "spec_helper"
+require "stringio"
module RSpec::Core::Formatters
@@ -32,7 +33,8 @@ module RSpec::Core::Formatters
group = RSpec::Core::ExampleGroup.describe
example = group.example { "this".should eq("that") }
formatter = RSpec::Core::Formatters::BaseTextFormatter.new(output)
- group.run_all(formatter)
+ notifier = RSpec::Core::Notifier.new(formatter)
+ group.run_all(notifier)
RSpec.configuration.stub(:color_enabled?) { false }
formatter.dump_failures

Showing you all comments on commits in this comparison.

@iromeo

It seems there is a typo. "!! in_block" is the same as "in_block"

@dchelimsky
Owner

If in_block is nil (as opposed to false), then in_block? returns nil. By saying !!in_block, in_block? will return false whether the value of in_block is nil or false.

So I wouldn't call this a typo :) It's actually a fairly common idiom in Ruby predicates.

@iromeo

Ok, sounds reasonable, I forgot about nil here.

Something went wrong with that request. Please try again.