diff --git a/lib/rspec/expectations/extensions.rb b/lib/rspec/expectations/extensions.rb index fba6aeb20..b25d298ac 100644 --- a/lib/rspec/expectations/extensions.rb +++ b/lib/rspec/expectations/extensions.rb @@ -1 +1,2 @@ require 'rspec/expectations/extensions/kernel' +require 'rspec/expectations/extensions/rspec/core/example_group' diff --git a/lib/rspec/expectations/extensions/rspec/core/example_group.rb b/lib/rspec/expectations/extensions/rspec/core/example_group.rb new file mode 100644 index 000000000..179988bdc --- /dev/null +++ b/lib/rspec/expectations/extensions/rspec/core/example_group.rb @@ -0,0 +1,19 @@ +module Rspec + module Core + class ExampleGroup + module BlockAliases + alias_method :to, :should + alias_method :to_not, :should_not + end + + # Extends the submitted block with aliases to and to_not + # for should and should_not. Allows expectations like this: + # + # expect { this_block }.to change{this.expression}.from(old_value).to(new_value) + # expect { this_block }.to raise_error + def expect(&block) + block.extend BlockAliases + end + end + end +end