Skip to content

Commit

Permalink
Move example actor class into a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Jun 30, 2012
1 parent ed33496 commit 9298dd7
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 77 deletions.
78 changes: 1 addition & 77 deletions spec/support/actor_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,7 @@ class ExampleCrash < StandardError
attr_accessor :foo
end

let :actor_class do
Class.new do
include included_module
attr_reader :name

def initialize(name)
@name = name
@delegate = [:bar]
end

def change_name(new_name)
@name = new_name
end

def change_name_async(new_name)
change_name! new_name
end

def greet
"Hi, I'm #{@name}"
end

def run(*args)
yield(*args)
end

def crash
raise ExampleCrash, "the spec purposely crashed me :("
end

def crash_with_abort(reason, foo = nil)
example_crash = ExampleCrash.new(reason)
example_crash.foo = foo
abort example_crash
end

def crash_with_abort_raw(reason)
abort reason
end

def internal_hello
external_hello
end

def external_hello
"Hello"
end

def method_missing(method_name, *args, &block)
if delegates?(method_name)
@delegate.send method_name, *args, &block
else
super
end
end

def respond_to?(method_name)
super || delegates?(method_name)
end

def call_private
zomg_private!
end

def zomg_private
@private_called = true
end
private :zomg_private
attr_reader :private_called

private

def delegates?(method_name)
@delegate.respond_to?(method_name)
end
end
end
let(:actor_class) { ExampleActorClass.create(included_module) }

it "returns the actor's class, not the proxy's" do
actor = actor_class.new "Troy McClure"
Expand Down
79 changes: 79 additions & 0 deletions spec/support/example_actor_class.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
module ExampleActorClass
def self.create(included_module)
Class.new do
include included_module
attr_reader :name

def initialize(name)
@name = name
@delegate = [:bar]
end

def change_name(new_name)
@name = new_name
end

def change_name_async(new_name)
change_name! new_name
end

def greet
"Hi, I'm #{@name}"
end

def run(*args)
yield(*args)
end

def crash
raise ExampleCrash, "the spec purposely crashed me :("
end

def crash_with_abort(reason, foo = nil)
example_crash = ExampleCrash.new(reason)
example_crash.foo = foo
abort example_crash
end

def crash_with_abort_raw(reason)
abort reason
end

def internal_hello
external_hello
end

def external_hello
"Hello"
end

def method_missing(method_name, *args, &block)
if delegates?(method_name)
@delegate.send method_name, *args, &block
else
super
end
end

def respond_to?(method_name)
super || delegates?(method_name)
end

def call_private
zomg_private!
end

def zomg_private
@private_called = true
end
private :zomg_private
attr_reader :private_called

private

def delegates?(method_name)
@delegate.respond_to?(method_name)
end
end
end
end

0 comments on commit 9298dd7

Please sign in to comment.