test/direction_test.rb in direction-0.0.3 vs test/direction_test.rb in direction-0.0.4
- old
+ new
@@ -1,11 +1,11 @@
require 'test_helper'
class Person
extend Direction
- command [:make_me_a_sandwich, :cook] => :@friend
- query [:activities, :go] => :friend
+ command [:make_me_a_sandwich, :cook, :blocky] => :@friend
+ query [:activities, :go, :say_what] => :friend
attr_accessor :friend
end
class Friend
def make_me_a_sandwich
@@ -21,10 +21,18 @@
end
def go(do_what)
Activities.record do_what
end
+
+ def blocky(text)
+ Activities.record([yield(self).to_s,text].join(' '))
+ end
+
+ def say_what(text)
+ [yield(self).to_s,text].join(' ')
+ end
end
module Menu
def self.record(text)
list << text
@@ -55,10 +63,11 @@
person.friend = friend
person
}
before do
Menu.clear
+ Activities.clear
end
it 'forwards a message to another object' do
assert_equal [], Menu.list
person.make_me_a_sandwich
assert_includes Menu.list, "I made a sandwich!"
@@ -71,10 +80,18 @@
it 'forwards additional arguments' do
assert_equal [], Menu.list
person.cook('yum')
assert_includes Menu.list, "yum"
end
+
+ it 'forwards block arguments' do
+ assert_equal [], Activities.list
+ person.blocky('yay!') do |friend|
+ "Arguments forwarded to #{friend}"
+ end
+ assert_includes Activities.list, "Arguments forwarded to #{friend} yay!"
+ end
end
describe Direction, 'query' do
let(:friend){ Friend.new }
let(:person){ person = Person.new
@@ -91,7 +108,15 @@
it 'forwards additional arguments' do
assert_equal [], Activities.list
person.go('have fun')
assert_includes Activities.list, "have fun"
+ end
+
+ it 'forwards block arguments' do
+ assert_equal [], Activities.list
+ what_said = person.say_what('yay!') do |friend|
+ "Arguments forwarded to #{friend}"
+ end
+ assert_equal what_said, "Arguments forwarded to #{friend} yay!"
end
end
\ No newline at end of file