Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully embrace _exec over _eval #290

Merged
merged 1 commit into from Jul 15, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/rspec/expectations/syntax.rb
Expand Up @@ -48,7 +48,7 @@ def default_should_host
def enable_should(syntax_host = default_should_host)
return if should_enabled?(syntax_host)

syntax_host.module_eval do
syntax_host.module_exec do
def should(matcher=nil, message=nil, &block)
::RSpec::Expectations::PositiveExpectationHandler.handle_matcher(self, matcher, message, &block)
end
Expand All @@ -66,7 +66,7 @@ def should_not(matcher=nil, message=nil, &block)
def disable_should(syntax_host = default_should_host)
return unless should_enabled?(syntax_host)

syntax_host.module_eval do
syntax_host.module_exec do
undef should
undef should_not
end
Expand All @@ -79,7 +79,7 @@ def disable_should(syntax_host = default_should_host)
def enable_expect(syntax_host = ::RSpec::Matchers)
return if expect_enabled?(syntax_host)

syntax_host.module_eval do
syntax_host.module_exec do
def expect(*target, &target_block)
target << target_block if block_given?
raise ArgumentError.new("You must pass an argument or a block to #expect but not both.") unless target.size == 1
Expand All @@ -95,7 +95,7 @@ def expect(*target, &target_block)
def disable_expect(syntax_host = ::RSpec::Matchers)
return unless expect_enabled?(syntax_host)

syntax_host.module_eval do
syntax_host.module_exec do
undef expect
end

Expand Down
4 changes: 2 additions & 2 deletions lib/rspec/matchers/compatibility.rb
@@ -1,12 +1,12 @@
RSpec::Matchers.constants.each do |c|
if Class === (klass = RSpec::Matchers.const_get(c))
if klass.public_instance_methods.any? {|m| ['failure_message_for_should',:failure_message_for_should].include?(m)}
klass.class_eval do
klass.class_exec do
alias_method :failure_message, :failure_message_for_should
end
end
if klass.public_instance_methods.any? {|m| ['failure_message_for_should_not',:failure_message_for_should_not].include?(m)}
klass.class_eval do
klass.class_exec do
alias_method :negative_failure_message, :failure_message_for_should_not
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/matchers/matcher.rb
Expand Up @@ -32,7 +32,7 @@ def initialize(name, &declarations)
# @api private
def for_expected(*expected)
@expected = expected
dup.instance_eval do
dup.instance_exec do
instance_variables.map {|ivar| ivar.intern}.each do |ivar|
instance_variable_set(ivar, nil) unless (PERSISTENT_INSTANCE_VARIABLES + [:@expected]).include?(ivar)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/rspec/matchers/matcher_spec.rb
Expand Up @@ -3,13 +3,13 @@
class UnexpectedError < StandardError; end
module MatcherHelperModule
def self.included(base)
base.module_eval do
base.module_exec do
def included_method; end
end
end

def self.extended(base)
base.instance_eval do
base.instance_exec do
def extended_method; end
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/rspec/matchers/yield_spec.rb
Expand Up @@ -52,7 +52,7 @@ def each_arg(*args, &block)
expect { |b| _yield_with_args(1, 2, &b) }.to yield_control
end

it 'passes if the block yields using instance_eval' do
it 'passes if the block yields using instance_exec' do
expect { |b| InstanceEvaler.new.yield_with_no_args(&b) }.to yield_control
end

Expand Down Expand Up @@ -190,7 +190,7 @@ def each_arg(*args, &block)
expect { |b| _yield_with_no_args(&b) }.to yield_with_no_args
end

it 'passes if the block yields with no args using instance_eval' do
it 'passes if the block yields with no args using instance_exec' do
expect { |b| InstanceEvaler.new.yield_with_no_args(&b) }.to yield_with_no_args
end

Expand Down Expand Up @@ -321,7 +321,7 @@ def each_arg(*args, &block)
expect { |b| _yield_with_args(3, 17, &b) }.to yield_with_args(3, 17)
end

it 'passes if the block yields with the given arguments using instance_eval' do
it 'passes if the block yields with the given arguments using instance_exec' do
expect { |b| InstanceEvaler.new.yield_with_args(3, 17, &b) }.to yield_with_args(3, 17)
end

Expand Down Expand Up @@ -361,7 +361,7 @@ def each_arg(*args, &block)
expect { |b| _yield_with_args(false, &b) }.to yield_with_args(false)
end

it 'passes if the block yields with the given arguments using instance_eval' do
it 'passes if the block yields with the given arguments using instance_exec' do
expect { |b| InstanceEvaler.new.yield_with_args(false, &b) }.to yield_with_args(false)
end

Expand Down Expand Up @@ -451,7 +451,7 @@ def each_arg(*args, &block)
expect { |b| [1, 2, 3].each(&b) }.to yield_successive_args(1, 2, 3)
end

it 'passes when the block successively yields the given args using instance_eval' do
it 'passes when the block successively yields the given args using instance_exec' do
expect { |b| InstanceEvaler.new.each_arg(1, 2, 3, &b) }.to yield_successive_args(1, 2, 3)
end

Expand Down