Skip to content

Commit

Permalink
move this into its own module, defined so it can be accessed either b…
Browse files Browse the repository at this point in the history
…y inclusion of TaskAuthor, or as TaskAuthor.in_order_to
  • Loading branch information
JonRowe committed May 6, 2011
1 parent 156c115 commit 70f9204
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 31 deletions.
25 changes: 17 additions & 8 deletions lib/cukesalad/task_author.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
require 'cukesalad/codify/const_name'
def in_order_to do_something, *with_attributes, &actions
attr_map = with_attributes[0]
name = Codify::ConstName.from do_something
m = Module.new do
define_method :perform_task, &actions
define_method :the do | value |
value_of( attr_map.key value )
module CukeSalad
module TaskAuthor

def in_order_to do_something, *with_attributes, &actions
TaskAuthor.in_order_to do_something, *with_attributes, &actions
end

def TaskAuthor.in_order_to do_something, *with_attributes, &actions
attr_map = with_attributes[0]
name = Codify::ConstName.from do_something
m = Module.new do
define_method :perform_task, &actions
define_method :the do | value |
value_of( attr_map.key value )
end
end
Kernel.const_set name, m
end
end
Kernel.const_set name, m
end
49 changes: 26 additions & 23 deletions spec/cukesalad/task_author_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,40 @@ def value_of thing
end
end

describe 'TaskAuthor' do
module CukeSalad
describe 'TaskAuthor' do
include TaskAuthor

it "creates a module by the same name" do
in_order_to "SomeTask" do;end
it "creates a module by the same name" do
in_order_to "SomeTask" do;end

SomeActor.new.see_how_to_do SomeTask
end

it "creates a module by a similar name" do
in_order_to "some different task" do;end
SomeActor.new.see_how_to_do SomeTask
end

SomeActor.new SomeDifferentTask
end
it "creates a module by a similar name" do
in_order_to "some different task" do;end

it "enables the actor to do something" do
in_order_to "SomeOtherTask" do
"done"
SomeActor.new SomeDifferentTask
end

actor = SomeActor.new
actor.see_how_to_do SomeOtherTask
actor.do_your_thing.should == "done"
end
it "enables the actor to do something" do
in_order_to "SomeOtherTask" do
"done"
end

it "maps some attributes" do
in_order_to "YetAnotherTask", with_info: :info do
the :info
actor = SomeActor.new
actor.see_how_to_do SomeOtherTask
actor.do_your_thing.should == "done"
end

actor = SomeActor.new
actor.see_how_to_do YetAnotherTask
actor.do_your_thing.should == "this is the info"
it "maps some attributes" do
in_order_to "YetAnotherTask", with_info: :info do
the :info
end

actor = SomeActor.new
actor.see_how_to_do YetAnotherTask
actor.do_your_thing.should == "this is the info"
end
end
end

0 comments on commit 70f9204

Please sign in to comment.