diff --git a/lib/cukesalad/task_author.rb b/lib/cukesalad/task_author.rb index c931cc2..49ce682 100644 --- a/lib/cukesalad/task_author.rb +++ b/lib/cukesalad/task_author.rb @@ -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 diff --git a/spec/cukesalad/task_author_spec.rb b/spec/cukesalad/task_author_spec.rb index dc25df4..fc0cdc2 100644 --- a/spec/cukesalad/task_author_spec.rb +++ b/spec/cukesalad/task_author_spec.rb @@ -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