Skip to content

Commit

Permalink
Merge 18bec05 into a4384bf
Browse files Browse the repository at this point in the history
  • Loading branch information
myronmarston committed Mar 20, 2014
2 parents a4384bf + 18bec05 commit d2b106b
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 127 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Expand Up @@ -23,6 +23,10 @@ Deprecations:
`RSpec::Core::ExampleGroup.description`. (Myron Marston)
* Deprecate `RSpec::Core::ExampleGroup.describes` in favor of
`RSpec::Core::ExampleGroup.described_class`. (Myron Marston)
* Deprecate `RSpec::Core::ExampleGroup.alias_example_to` in favor of
`RSpec::Core::Configuration#alias_example_to`. (Myron Marston)
* Deprecate `RSpec::Core::ExampleGroup.alias_it_behaves_like_to` in favor
of `RSpec::Core::Configuration#alias_it_behaves_like_to`. (Myron Marston)

### 2.99.0.beta2 / 2014-02-17
[full changelog](http://github.com/rspec/rspec-core/compare/v2.99.0.beta1...v2.99.0.beta2)
Expand Down
5 changes: 3 additions & 2 deletions lib/rspec/core/configuration.rb
Expand Up @@ -280,6 +280,7 @@ def initialize
@profile_examples = false
@requires = []
@libs = []
@show_failures_in_pending_blocks = false
end

# @private
Expand Down Expand Up @@ -730,7 +731,7 @@ def files_or_directories_to_run=(*files)
# end
def alias_example_to(new_name, *args)
extra_options = build_metadata_hash_from(args)
RSpec::Core::ExampleGroup.alias_example_to(new_name, extra_options)
RSpec::Core::ExampleGroup.define_example_method(new_name, extra_options)
end

# Define an alias for it_should_behave_like that allows different
Expand All @@ -755,7 +756,7 @@ def alias_example_to(new_name, *args)
# has behavior: sortability
# # sortability examples here
def alias_it_behaves_like_to(new_name, report_label = '')
RSpec::Core::ExampleGroup.alias_it_behaves_like_to(new_name, report_label)
RSpec::Core::ExampleGroup.define_nested_shared_group_method(new_name, report_label)
end

alias_method :alias_it_should_behave_like_to, :alias_it_behaves_like_to
Expand Down
250 changes: 127 additions & 123 deletions lib/rspec/core/example_group.rb
Expand Up @@ -63,136 +63,140 @@ def describes
:replacement => "`RSpec::Core::ExampleGroup.described_class`")
described_class
end
end

# @private
# @macro [attach] define_example_method
# @param [String] name
# @param [Hash] extra_options
# @param [Block] implementation
# @yield [Example] the example object
def self.define_example_method(name, extra_options={})
module_eval(<<-END_RUBY, __FILE__, __LINE__)
def #{name}(desc=nil, *args, &block)
if #{name.inspect} == :pending
RSpec.warn_deprecation(<<-EOS.gsub(/^\s+\\|/, ''))
|The semantics of `RSpec::Core::ExampleGroup#pending` are changing in RSpec 3.
|In RSpec 2.x, it caused the example to be skipped. In RSpec 3, the example will
|still be run but is expected to fail, and will be marked as a failure (rather
|than as pending) if the example passes, just like how `pending` with a block
|from within an example already works.
|
|To keep the same skip semantics, change `pending` to `skip`. Otherwise, if you
|want the new RSpec 3 behavior, you can safely ignore this warning and continue
|to upgrade to RSpec 3 without addressing it.
|
|Called from \#{CallerFilter.first_non_rspec_line}.
|
EOS
end
options = build_metadata_hash_from(args)
options.update(:pending => RSpec::Core::Pending::NOT_YET_IMPLEMENTED) unless block
options.update(#{extra_options.inspect})
examples << RSpec::Core::Example.new(self, desc, options, block)
examples.last
# @private
# @macro [attach] define_example_method
# @param [String] name
# @param [Hash] extra_options
# @param [Block] implementation
# @yield [Example] the example object
def self.define_example_method(name, extra_options={})
module_eval(<<-END_RUBY, __FILE__, __LINE__)
def self.#{name}(desc=nil, *args, &block)
if #{name.inspect} == :pending
RSpec.warn_deprecation(<<-EOS.gsub(/^\s+\\|/, ''))
|The semantics of `RSpec::Core::ExampleGroup#pending` are changing in RSpec 3.
|In RSpec 2.x, it caused the example to be skipped. In RSpec 3, the example will
|still be run but is expected to fail, and will be marked as a failure (rather
|than as pending) if the example passes, just like how `pending` with a block
|from within an example already works.
|
|To keep the same skip semantics, change `pending` to `skip`. Otherwise, if you
|want the new RSpec 3 behavior, you can safely ignore this warning and continue
|to upgrade to RSpec 3 without addressing it.
|
|Called from \#{CallerFilter.first_non_rspec_line}.
|
EOS
end
END_RUBY
end
options = build_metadata_hash_from(args)
options.update(:pending => RSpec::Core::Pending::NOT_YET_IMPLEMENTED) unless block
options.update(#{extra_options.inspect})
examples << RSpec::Core::Example.new(self, desc, options, block)
examples.last
end
END_RUBY
end

# Defines an example within a group.
# @example
# example do
# end
#
# example "does something" do
# end
#
# example "does something", :with => 'additional metadata' do
# end
#
# example "does something" do |ex|
# # ex is the Example object that evals this block
# end
define_example_method :example
# Defines an example within a group.
# @example
define_example_method :it
# Defines an example within a group.
# This is here primarily for backward compatibility with early versions
# of RSpec which used `context` and `specify` instead of `describe` and
# `it`.
define_example_method :specify

# Shortcut to define an example with `:focus` => true
# @see example
define_example_method :focus, :focused => true, :focus => true
# Shortcut to define an example with `:focus` => true
# @see example
define_example_method :focused, :focused => true, :focus => true
# Shortcut to define an example with `:focus` => true
# @see example
define_example_method :fit, :focused => true, :focus => true

# Shortcut to define an example with :pending => true
# @see example
define_example_method :pending, :pending => true
# Shortcut to define an example with :pending => true
# Backported from RSpec 3 to aid migration.
# @see example
define_example_method :skip, :pending => true
# Shortcut to define an example with :pending => 'Temporarily disabled with xexample'
# @see example
define_example_method :xexample, :pending => 'Temporarily disabled with xexample'
# Shortcut to define an example with :pending => 'Temporarily disabled with xit'
# @see example
define_example_method :xit, :pending => 'Temporarily disabled with xit'
# Shortcut to define an example with :pending => 'Temporarily disabled with xspecify'
# @see example
define_example_method :xspecify, :pending => 'Temporarily disabled with xspecify'

# Works like `alias_method :name, :example` with the added benefit of
# assigning default metadata to the generated example.
#
# @note Use with caution. This extends the language used in your
# specs, but does not add any additional documentation. We use this
# in rspec to define methods like `focus` and `xit`, but we also add
# docs for those methods.
def alias_example_to name, extra={}
(class << self; self; end).define_example_method name, extra
end
# Defines an example within a group.
# @example
# example do
# end
#
# example "does something" do
# end
#
# example "does something", :with => 'additional metadata' do
# end
#
# example "does something" do |ex|
# # ex is the Example object that evals this block
# end
define_example_method :example
# Defines an example within a group.
# @example
define_example_method :it
# Defines an example within a group.
# This is here primarily for backward compatibility with early versions
# of RSpec which used `context` and `specify` instead of `describe` and
# `it`.
define_example_method :specify

# Shortcut to define an example with `:focus` => true
# @see example
define_example_method :focus, :focused => true, :focus => true
# Shortcut to define an example with `:focus` => true
# @see example
define_example_method :focused, :focused => true, :focus => true
# Shortcut to define an example with `:focus` => true
# @see example
define_example_method :fit, :focused => true, :focus => true

# Shortcut to define an example with :pending => true
# @see example
define_example_method :pending, :pending => true
# Shortcut to define an example with :pending => true
# Backported from RSpec 3 to aid migration.
# @see example
define_example_method :skip, :pending => true
# Shortcut to define an example with :pending => 'Temporarily disabled with xexample'
# @see example
define_example_method :xexample, :pending => 'Temporarily disabled with xexample'
# Shortcut to define an example with :pending => 'Temporarily disabled with xit'
# @see example
define_example_method :xit, :pending => 'Temporarily disabled with xit'
# Shortcut to define an example with :pending => 'Temporarily disabled with xspecify'
# @see example
define_example_method :xspecify, :pending => 'Temporarily disabled with xspecify'

# Works like `alias_method :name, :example` with the added benefit of
# assigning default metadata to the generated example.
#
# @note Use with caution. This extends the language used in your
# specs, but does not add any additional documentation. We use this
# in rspec to define methods like `focus` and `xit`, but we also add
# docs for those methods.
def self.alias_example_to name, extra={}
RSpec.deprecate("`RSpec::Core::ExampleGroup.alias_example_to`",
:replacement => "`RSpec::Core::Configuration#alias_example_to`")
define_example_method name, extra
end

# @private
# @macro [attach] define_nested_shared_group_method
#
# @see SharedExampleGroup
def self.define_nested_shared_group_method(new_name, report_label=nil)
module_eval(<<-END_RUBY, __FILE__, __LINE__)
def #{new_name}(name, *args, &customization_block)
group = describe("#{report_label || "it should behave like"} \#{name}") do
find_and_eval_shared("examples", name, *args, &customization_block)
end
group.metadata[:shared_group_name] = name
group
# @private
# @macro [attach] define_nested_shared_group_method
#
# @see SharedExampleGroup
def self.define_nested_shared_group_method(new_name, report_label=nil)
module_eval(<<-END_RUBY, __FILE__, __LINE__)
def self.#{new_name}(name, *args, &customization_block)
group = describe("#{report_label || "it should behave like"} \#{name}") do
find_and_eval_shared("examples", name, *args, &customization_block)
end
END_RUBY
end
group.metadata[:shared_group_name] = name
group
end
END_RUBY
end

# Generates a nested example group and includes the shared content
# mapped to `name` in the nested group.
define_nested_shared_group_method :it_behaves_like, "behaves like"
# Generates a nested example group and includes the shared content
# mapped to `name` in the nested group.
define_nested_shared_group_method :it_should_behave_like
# Generates a nested example group and includes the shared content
# mapped to `name` in the nested group.
define_nested_shared_group_method :it_behaves_like, "behaves like"
# Generates a nested example group and includes the shared content
# mapped to `name` in the nested group.
define_nested_shared_group_method :it_should_behave_like

# Works like `alias_method :name, :it_behaves_like` with the added
# benefit of assigning default metadata to the generated example.
#
# @note Use with caution. This extends the language used in your
# specs, but does not add any additional documentation. We use this
# in rspec to define `it_should_behave_like` (for backward
# compatibility), but we also add docs for that method.
def alias_it_behaves_like_to name, *args, &block
(class << self; self; end).define_nested_shared_group_method name, *args, &block
end
# Works like `alias_method :name, :it_behaves_like` with the added
# benefit of assigning default metadata to the generated example.
#
# @note Use with caution. This extends the language used in your
# specs, but does not add any additional documentation. We use this
# in rspec to define `it_should_behave_like` (for backward
# compatibility), but we also add docs for that method.
def self.alias_it_behaves_like_to name, *args, &block
RSpec.deprecate("`RSpec::Core::ExampleGroup.alias_it_behaves_like_to`",
:replacement => "`RSpec::Core::Configuration#alias_it_behaves_like_to`")
define_nested_shared_group_method name, *args, &block
end

# Includes shared content mapped to `name` directly in the group in which
Expand Down
14 changes: 14 additions & 0 deletions spec/rspec/core/example_group_spec.rb
Expand Up @@ -1293,6 +1293,20 @@ def foo; end
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /display_name/)
expect(self.class.display_name).to eq(self.class.description)
end

specify ".alias_it_behaves_like_to is deprecated" do
expect_deprecation_with_call_site(__FILE__, __LINE__ + 2, /alias_it_behaves_like_to/)
expect {
ExampleGroup.alias_it_behaves_like_to(:it_does_something, "it does something")
}.to change { ExampleGroup.respond_to?(:it_does_something) }.from(false).to(true)
end

specify ".alias_example_to is deprecated" do
expect_deprecation_with_call_site(__FILE__, __LINE__ + 2, /alias_example_to/)
expect {
ExampleGroup.alias_example_to(:an_example)
}.to change { ExampleGroup.respond_to?(:an_example) }.from(false).to(true)
end
end
end
end
8 changes: 7 additions & 1 deletion spec/rspec/core/formatters/html_formatter_spec.rb
Expand Up @@ -24,8 +24,14 @@ module Formatters
out.set_encoding("utf-8") if out.respond_to?(:set_encoding)

command_line = RSpec::Core::CommandLine.new(options)
command_line.instance_variable_get("@configuration").backtrace_cleaner.inclusion_patterns = []
configuration = command_line.instance_variable_get(:@configuration)

configuration.backtrace_cleaner.inclusion_patterns = []
configuration.output_stream = out
configuration.deprecation_stream = err

command_line.run(err, out)

html = out.string.gsub(/\d+\.\d+(s| seconds)/, "n.nnnn\\1")

actual_doc = Nokogiri::HTML(html)
Expand Down
7 changes: 6 additions & 1 deletion spec/rspec/core/formatters/text_mate_formatter_spec.rb
Expand Up @@ -24,7 +24,12 @@ module Formatters
out.set_encoding("utf-8") if out.respond_to?(:set_encoding)

command_line = RSpec::Core::CommandLine.new(options)
command_line.instance_variable_get("@configuration").backtrace_cleaner.inclusion_patterns = []
configuration = command_line.instance_variable_get(:@configuration)

configuration.backtrace_cleaner.inclusion_patterns = []
configuration.output_stream = out
configuration.deprecation_stream = err

command_line.run(err, out)
html = out.string.gsub(/\d+\.\d+(s| seconds)/, "n.nnnn\\1")

Expand Down

0 comments on commit d2b106b

Please sign in to comment.