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

Clean up a little bit the code #48

Merged
merged 3 commits into from
Jan 26, 2014
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/naught/basic_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ class BasicObject < ::BasicObject
end
else
class BasicObject #:nodoc:
keep = %w[! != == __id__ __send__ equal? instance_eval instance_exec method_missing singleton_method_added singleton_method_removed singleton_method_undefined]
keep = %w[
! != == __id__ __send__ equal? instance_eval instance_exec
method_missing singleton_method_added singleton_method_removed
singleton_method_undefined
]
instance_methods.each do |method_name|
undef_method(method_name) unless keep.include?(method_name)
end
Expand Down
3 changes: 1 addition & 2 deletions lib/naught/null_class_builder/commands/impersonate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ module Naught::NullClassBuilder::Commands
class Impersonate < Naught::NullClassBuilder::Commands::Mimic
def initialize(builder, class_to_impersonate, options = {})
super

builder.base_class = class_to_impersonate
builder.base_class = class_to_impersonate
end
end
end
6 changes: 1 addition & 5 deletions lib/naught/null_class_builder/commands/mimic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ def call
private

def root_class_of(klass)
if klass.ancestors.include?(Object)
Object
else
Naught::BasicObject
end
klass.ancestors.include?(Object) ? Object : Naught::BasicObject
end

def methods_to_stub
Expand Down
3 changes: 1 addition & 2 deletions lib/naught/null_class_builder/commands/predicates_return.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def define_method_missing(subject)
subject.module_exec(@predicate_return_value) do |return_value|
if subject.method_defined?(:method_missing)
original_method_missing = instance_method(:method_missing)
define_method(:method_missing) do
|method_name, *args, &block|
define_method(:method_missing) do |method_name, *args, &block|
if method_name.to_s.end_with?('?')
return_value
else
Expand Down
7 changes: 2 additions & 5 deletions lib/naught/null_class_builder/commands/traceable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ def call
attr_reader :__file__, :__line__

def initialize(options = {})
backtrace = if RUBY_VERSION.to_f == 1.9 && RUBY_PLATFORM != 'java'
options.fetch(:caller) { Kernel.caller(4) }
else
options.fetch(:caller) { Kernel.caller(3) }
end
range = (RUBY_VERSION.to_f == 1.9 && RUBY_PLATFORM != 'java') ? 4 : 3
backtrace = options.fetch(:caller) { Kernel.caller(range) }
@__file__, line, _ = backtrace[0].split(':')
@__line__ = line.to_i
end
Expand Down
6 changes: 4 additions & 2 deletions spec/pebble_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def call_method_inside_nested_block(thing)
end

context 'when is called from a block' do
it 'prints the indication of a block', :pending => jruby? || rubinius? || ruby_18? do
it 'prints the indication of a block',
:pending => jruby? || rubinius? || ruby_18? do
expect(test_output).to receive(:puts).twice.
with(/from block/)
Caller.new.call_method_inside_block(null)
Expand All @@ -60,7 +61,8 @@ def call_method_inside_nested_block(thing)
end

context 'when is called from many levels blocks' do
it 'prints the indication of blocks and its levels', :pending => jruby? || rubinius? || ruby_18? do
it 'prints the indication of blocks and its levels',
:pending => jruby? || rubinius? || ruby_18? do
expect(test_output).to receive(:puts).exactly(4).times.
with(/from block \(2 levels\)/)
Caller.new.call_method_inside_nested_block(null)
Expand Down