cukesalad 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +15 -0
- data/Examples/Calculator/Gemfile +4 -5
- data/Examples/Calculator/Gemfile.lock +30 -33
- data/Examples/Calculator/features/lib/default/tasks/{add.rb → arithmetic/add.rb} +0 -0
- data/Examples/Calculator/features/lib/default/tasks/{calculate.rb → arithmetic/calculate.rb} +0 -0
- data/Examples/Calculator/features/lib/default/tasks/{subtract.rb → arithmetic/subtract.rb} +0 -0
- data/Examples/Calculator/features/lib/default/tasks/{see_the_answer.rb → questions/see_the_answer.rb} +0 -0
- data/Examples/Calculator/features/lib/default/tasks/{calculations.rb → reference/calculations.rb} +0 -0
- data/Gemfile +2 -7
- data/Gemfile.lock +29 -29
- data/Rakefile +1 -21
- data/cukesalad.gemspec +29 -0
- data/features/define_a_task.feature +17 -17
- data/features/remember_information_between_steps.feature +5 -5
- data/features/support/env.rb +0 -2
- data/lib/cukesalad.rb +2 -36
- data/lib/cukesalad/actor.rb +49 -0
- data/lib/cukesalad/codify/const_name.rb +23 -0
- data/lib/cukesalad/cucumber.rb +35 -0
- data/lib/cukesalad/director.rb +30 -0
- data/lib/cukesalad/salad.rb +3 -0
- data/lib/cukesalad/specifics.rb +36 -0
- data/lib/cukesalad/task_author.rb +21 -0
- data/lib/cukesalad/version.rb +3 -0
- data/spec/cukesalad/actor_spec.rb +96 -0
- data/spec/cukesalad/codify/as_const_name_spec.rb +30 -0
- data/spec/cukesalad/director_spec.rb +36 -0
- data/spec/cukesalad/specifics_spec.rb +68 -0
- data/spec/cukesalad/task_author_spec.rb +52 -0
- data/spec/spec_helper.rb +1 -4
- metadata +62 -59
- data/examples/Calculator/features/lib/alternative/roles/calculating_web_user.rb +0 -55
- data/examples/Calculator/features/lib/default/roles/calculating_individual.rb +0 -32
- data/examples/Calculator/features/lib/default/tasks/add.rb +0 -6
- data/examples/Calculator/features/lib/default/tasks/calculate.rb +0 -4
- data/examples/Calculator/features/lib/default/tasks/calculations.rb +0 -15
- data/examples/Calculator/features/lib/default/tasks/see_the_answer.rb +0 -3
- data/examples/Calculator/features/lib/default/tasks/subtract.rb +0 -4
- data/examples/Calculator/features/lib/default/tasks/switch_on_the_calculator.rb +0 -9
- data/examples/Calculator/features/support/env.rb +0 -5
- data/examples/Calculator/lib/calculator.rb +0 -53
- data/examples/Calculator/lib/web_calculator.rb +0 -82
- data/examples/Calculator/spec/calculator_spec.rb +0 -73
- data/examples/Calculator/spec/web_calculator_spec.rb +0 -99
- data/lib/actor.rb +0 -47
- data/lib/codify/const_name.rb +0 -21
- data/lib/director.rb +0 -28
- data/lib/specifics.rb +0 -34
- data/lib/task_author.rb +0 -12
- data/spec/actor_spec.rb +0 -96
- data/spec/codify/as_const_name_spec.rb +0 -28
- data/spec/director_spec.rb +0 -34
- data/spec/specifics_spec.rb +0 -67
- data/spec/task_author_spec.rb +0 -50
@@ -1,73 +0,0 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
-
require 'rubygems'
|
3
|
-
require 'bundler'
|
4
|
-
Bundler.setup
|
5
|
-
require 'calculator'
|
6
|
-
|
7
|
-
describe Calculator do
|
8
|
-
|
9
|
-
it "starts with zero" do
|
10
|
-
calc = Calculator.new
|
11
|
-
|
12
|
-
calc.display.should == 0
|
13
|
-
end
|
14
|
-
|
15
|
-
it "shows the current number" do
|
16
|
-
calc = Calculator.new
|
17
|
-
calc.enter 1
|
18
|
-
|
19
|
-
calc.display.should == 1
|
20
|
-
end
|
21
|
-
|
22
|
-
it "displays the same when equals alone is pressed" do
|
23
|
-
calc = Calculator.new
|
24
|
-
calc.enter 1
|
25
|
-
|
26
|
-
calc.equals
|
27
|
-
|
28
|
-
calc.display.should == 1
|
29
|
-
end
|
30
|
-
|
31
|
-
it "treats 1 + = like 1 + 1 =" do
|
32
|
-
calc = Calculator.new
|
33
|
-
|
34
|
-
calc.enter 1
|
35
|
-
calc.get_ready_to :+
|
36
|
-
calc.equals
|
37
|
-
|
38
|
-
calc.display.should == 2
|
39
|
-
end
|
40
|
-
|
41
|
-
it "repeats the last operation" do
|
42
|
-
calc = Calculator.new
|
43
|
-
calc.enter 1
|
44
|
-
calc.get_ready_to :+
|
45
|
-
calc.equals
|
46
|
-
calc.equals
|
47
|
-
calc.display.should == 3
|
48
|
-
end
|
49
|
-
|
50
|
-
it "starts again when you enter a number after equals" do
|
51
|
-
calc = Calculator.new
|
52
|
-
calc.enter 1
|
53
|
-
calc.get_ready_to :+
|
54
|
-
calc.enter 1
|
55
|
-
calc.equals
|
56
|
-
calc.enter 5
|
57
|
-
calc.get_ready_to :+
|
58
|
-
calc.equals
|
59
|
-
|
60
|
-
calc.display.should == 10
|
61
|
-
end
|
62
|
-
|
63
|
-
it "calculate what it has so far" do
|
64
|
-
calc = Calculator.new
|
65
|
-
calc.enter 1
|
66
|
-
calc.get_ready_to :+
|
67
|
-
calc.enter 1
|
68
|
-
calc.get_ready_to :+
|
69
|
-
|
70
|
-
calc.display.should == 2
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
@@ -1,99 +0,0 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__) + '/../lib/')
|
2
|
-
require 'web_calculator'
|
3
|
-
require 'capybara'
|
4
|
-
require 'capybara/dsl'
|
5
|
-
|
6
|
-
Capybara.app = WebCalculator
|
7
|
-
Capybara.default_driver = :rack_test
|
8
|
-
|
9
|
-
describe "WebCalculator", :type => :request do
|
10
|
-
|
11
|
-
include Capybara
|
12
|
-
|
13
|
-
before(:each) do
|
14
|
-
Capybara.reset_sessions!
|
15
|
-
end
|
16
|
-
|
17
|
-
context "homepage" do
|
18
|
-
it "is successful" do
|
19
|
-
visit '/'
|
20
|
-
page.should have_content 'Calculator is Ready!'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def calculator_display
|
25
|
-
find_field('display').value.to_i
|
26
|
-
end
|
27
|
-
|
28
|
-
context "storing calculator display state" do
|
29
|
-
it "starts with nothing" do
|
30
|
-
visit '/'
|
31
|
-
calculator_display.should == 0
|
32
|
-
end
|
33
|
-
|
34
|
-
it "udpates the display when an operator is pressed" do
|
35
|
-
visit '/'
|
36
|
-
fill_in 'number', :with => '10'
|
37
|
-
click_button 'minus'
|
38
|
-
calculator_display.should == 10
|
39
|
-
end
|
40
|
-
|
41
|
-
it "updates the display when a different different operator is pressed" do
|
42
|
-
visit '/'
|
43
|
-
fill_in 'number', :with => '15'
|
44
|
-
click_button 'plus'
|
45
|
-
calculator_display.should == 15
|
46
|
-
end
|
47
|
-
|
48
|
-
it "updates the display when a sequence of operators are entered" do
|
49
|
-
visit '/'
|
50
|
-
fill_in 'number', :with => '1'
|
51
|
-
click_button 'plus'
|
52
|
-
fill_in 'number', :with => '1'
|
53
|
-
click_button 'plus'
|
54
|
-
calculator_display.should == 2
|
55
|
-
end
|
56
|
-
|
57
|
-
it "persists the display between requests" do
|
58
|
-
visit '/'
|
59
|
-
fill_in 'number', :with => '15'
|
60
|
-
click_button 'plus'
|
61
|
-
calculator_display.should == 15
|
62
|
-
visit '/'
|
63
|
-
calculator_display.should == 15
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "doing simple arithmetic" do
|
68
|
-
it "adds two numbers" do
|
69
|
-
visit '/'
|
70
|
-
fill_in 'number', :with => '1'
|
71
|
-
click_button 'plus'
|
72
|
-
fill_in 'number', :with => '0'
|
73
|
-
click_button 'equals'
|
74
|
-
calculator_display.should == 1
|
75
|
-
end
|
76
|
-
|
77
|
-
it "adds two of the same number" do
|
78
|
-
visit '/'
|
79
|
-
fill_in 'number', :with => '1'
|
80
|
-
click_button 'plus'
|
81
|
-
fill_in 'number', :with => '1'
|
82
|
-
click_button 'equals'
|
83
|
-
calculator_display.should == 2
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
context "doing meta calculations" do
|
88
|
-
it "allows double equals calculator functionality" do
|
89
|
-
visit '/'
|
90
|
-
fill_in 'number', :with => '1'
|
91
|
-
click_button 'plus'
|
92
|
-
click_button 'equals'
|
93
|
-
calculator_display.should == 2
|
94
|
-
click_button 'equals'
|
95
|
-
calculator_display.should == 3
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
data/lib/actor.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'director'
|
2
|
-
|
3
|
-
class Actor
|
4
|
-
|
5
|
-
def initialize this_type_of_role, directed_by=Director.new
|
6
|
-
@director = directed_by
|
7
|
-
get_into_character_for this_type_of_role
|
8
|
-
@note_pad = {}
|
9
|
-
end
|
10
|
-
|
11
|
-
def perform described_task, details = {}
|
12
|
-
get_ready_to_perform described_task
|
13
|
-
@info = details
|
14
|
-
perform_task
|
15
|
-
end
|
16
|
-
alias :answer :perform
|
17
|
-
|
18
|
-
def get_into_character_for described_role
|
19
|
-
the_role = @director.explain_the_role described_role
|
20
|
-
see_how_to_do the_role
|
21
|
-
end
|
22
|
-
|
23
|
-
def get_ready_to_perform something
|
24
|
-
the_thing = @director.how_do_i_perform something
|
25
|
-
see_how_to_do the_thing
|
26
|
-
end
|
27
|
-
|
28
|
-
def see_how_to_do something
|
29
|
-
extend something
|
30
|
-
end
|
31
|
-
|
32
|
-
def value_of(symbol)
|
33
|
-
@info[symbol]
|
34
|
-
end
|
35
|
-
|
36
|
-
def take_note_of key, value
|
37
|
-
@note_pad.store key, value
|
38
|
-
end
|
39
|
-
|
40
|
-
def recall key
|
41
|
-
begin
|
42
|
-
@note_pad.fetch key
|
43
|
-
rescue KeyError
|
44
|
-
raise KeyError, "You tried to recall ':#{key}' but no previous step appears to have taken note of that information."
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
data/lib/codify/const_name.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
module Codify
|
2
|
-
module ConstName
|
3
|
-
def ConstName.from sentence
|
4
|
-
joined_together capitalised( words_from sentence )
|
5
|
-
end
|
6
|
-
|
7
|
-
private
|
8
|
-
def ConstName.joined_together words
|
9
|
-
words.join
|
10
|
-
end
|
11
|
-
|
12
|
-
def ConstName.words_from this_sentence
|
13
|
-
on_word_boundary = /\s|([A-Z][a-z]+)/
|
14
|
-
this_sentence.split( on_word_boundary )
|
15
|
-
end
|
16
|
-
|
17
|
-
def ConstName.capitalised words
|
18
|
-
words.collect{ | word | word.capitalize }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/lib/director.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'codify/const_name'
|
2
|
-
class Director
|
3
|
-
|
4
|
-
include Codify
|
5
|
-
|
6
|
-
#TODO: Needs refactoring
|
7
|
-
def explain_the_role description
|
8
|
-
name = ConstName.from description
|
9
|
-
begin
|
10
|
-
find_directives_for name
|
11
|
-
rescue NameError
|
12
|
-
raise "I can't find a role called '#{ name }'. Have you created it?\ne.g.\n module #{ name }\n end"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def how_do_i_perform something
|
17
|
-
name = ConstName.from something
|
18
|
-
begin
|
19
|
-
find_directives_for name
|
20
|
-
rescue NameError
|
21
|
-
raise "I can't find a task called '#{ something }'. Have you created it?\ne.g.\n in_order_to '#{ something }' do\n # the actions\n end"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def find_directives_for something
|
26
|
-
Kernel.const_get( something )
|
27
|
-
end
|
28
|
-
end
|
data/lib/specifics.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
module Specifics
|
2
|
-
def understand_the details
|
3
|
-
@info = with_specifics_from( details )
|
4
|
-
end
|
5
|
-
|
6
|
-
def value_of(symbol)
|
7
|
-
@info[symbol]
|
8
|
-
end
|
9
|
-
|
10
|
-
def with_specifics_from details
|
11
|
-
result = {}
|
12
|
-
names_and_values_in(details).each_slice(2) do |name_value|
|
13
|
-
result[symbolized name_value[0]] = the_value_from_the name_value[1]
|
14
|
-
end
|
15
|
-
result
|
16
|
-
end
|
17
|
-
|
18
|
-
def set_last value
|
19
|
-
@info[@info.keys.last] = value
|
20
|
-
end
|
21
|
-
|
22
|
-
def names_and_values_in details
|
23
|
-
specifics_pattern = /('[^']+')/
|
24
|
-
details.split(specifics_pattern)
|
25
|
-
end
|
26
|
-
|
27
|
-
def symbolized name
|
28
|
-
name.strip.gsub(' ', '_').to_sym
|
29
|
-
end
|
30
|
-
|
31
|
-
def the_value_from_the item
|
32
|
-
item.gsub(/(^'|'$)/, '') unless item.nil?
|
33
|
-
end
|
34
|
-
end
|
data/lib/task_author.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'codify/const_name'
|
2
|
-
def in_order_to do_something, *with_attributes, &actions
|
3
|
-
attr_map = with_attributes[0]
|
4
|
-
name = Codify::ConstName.from do_something
|
5
|
-
m = Module.new do
|
6
|
-
define_method :perform_task, &actions
|
7
|
-
define_method :the do | value |
|
8
|
-
value_of( attr_map.key value )
|
9
|
-
end
|
10
|
-
end
|
11
|
-
Kernel.const_set name, m
|
12
|
-
end
|
data/spec/actor_spec.rb
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__), ".")
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
module SetThePlaceAtTheTable
|
5
|
-
|
6
|
-
def perform_task
|
7
|
-
place = []
|
8
|
-
place_the_fork_on_the_left_of place
|
9
|
-
place_the_knife_on_the_right_of place
|
10
|
-
place
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
module LayTheTable
|
15
|
-
|
16
|
-
def perform_task
|
17
|
-
value_of( :with_places_for ).to_i
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
module Butler
|
22
|
-
|
23
|
-
def place_the_fork_on_the_left_of place
|
24
|
-
place.unshift "fork"
|
25
|
-
end
|
26
|
-
|
27
|
-
def place_the_knife_on_the_right_of place
|
28
|
-
place.push "knife"
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
describe Actor do
|
34
|
-
|
35
|
-
it "gets into character" do
|
36
|
-
role_description = "Butler"
|
37
|
-
director = double("director")
|
38
|
-
director.should_receive( :explain_the_role ).with( role_description ).and_return( Butler )
|
39
|
-
|
40
|
-
actor = Actor.new role_description, director
|
41
|
-
end
|
42
|
-
|
43
|
-
it "performs a simple task as that character" do
|
44
|
-
role_description = "Butler"
|
45
|
-
|
46
|
-
task_description = "set the place at the table"
|
47
|
-
|
48
|
-
director = double("director")
|
49
|
-
director.should_receive( :explain_the_role ).with( role_description ).and_return( Butler )
|
50
|
-
director.should_receive( :how_do_i_perform ).with( task_description ).and_return( SetThePlaceAtTheTable )
|
51
|
-
|
52
|
-
actor = Actor.new role_description, director
|
53
|
-
|
54
|
-
actor.perform(task_description).should == ["fork","knife"]
|
55
|
-
end
|
56
|
-
|
57
|
-
it "can perform a task that requires certain details" do
|
58
|
-
role_description = "Butler"
|
59
|
-
|
60
|
-
task_description = "Lay The Table"
|
61
|
-
details = { with_places_for: '5' }
|
62
|
-
|
63
|
-
director = double("director")
|
64
|
-
director.should_receive( :explain_the_role ).with( role_description ).and_return( Butler )
|
65
|
-
director.should_receive( :how_do_i_perform ).with( task_description ).and_return( LayTheTable )
|
66
|
-
|
67
|
-
actor = Actor.new role_description, director
|
68
|
-
|
69
|
-
actor.perform( task_description, details ).should == 5
|
70
|
-
end
|
71
|
-
|
72
|
-
it "can take note of information" do
|
73
|
-
role_description = "Butler"
|
74
|
-
|
75
|
-
director = double("director")
|
76
|
-
director.should_receive( :explain_the_role ).with( role_description ).and_return( Butler )
|
77
|
-
|
78
|
-
actor = Actor.new role_description, director
|
79
|
-
|
80
|
-
actor.take_note_of :something, "of importance"
|
81
|
-
actor.recall( :something ).should == "of importance"
|
82
|
-
end
|
83
|
-
|
84
|
-
it "tells you when it can't find the information you're looking for" do
|
85
|
-
role_description = "Butler"
|
86
|
-
|
87
|
-
director = double("director")
|
88
|
-
director.should_receive( :explain_the_role ).with( role_description ).and_return( Butler )
|
89
|
-
|
90
|
-
actor = Actor.new role_description, director
|
91
|
-
|
92
|
-
lambda {actor.recall( :something )}.should raise_error KeyError,
|
93
|
-
"You tried to recall ':something' but no previous step appears to have taken note of that information."
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
@@ -1,28 +0,0 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__), ".")
|
2
|
-
require 'spec_helper'
|
3
|
-
require 'codify/const_name'
|
4
|
-
|
5
|
-
describe Codify::ConstName do
|
6
|
-
include Codify
|
7
|
-
|
8
|
-
it "gives you ClassName from when it's already a class name" do
|
9
|
-
ConstName.from( "ClassName" ).should == "ClassName"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "gives you ClassName when separated by spaces" do
|
13
|
-
ConstName.from( "Class Name" ).should == "ClassName"
|
14
|
-
end
|
15
|
-
|
16
|
-
it "gives you ClassName from lowercase class name" do
|
17
|
-
ConstName.from( "class name" ).should == "ClassName"
|
18
|
-
end
|
19
|
-
|
20
|
-
it "gives you ClassName from lower case class name with leading/trailing spaces" do
|
21
|
-
ConstName.from( " class name " ).should == "ClassName"
|
22
|
-
end
|
23
|
-
|
24
|
-
it "formats as a ClassName from a mix of class format and lower case" do
|
25
|
-
ConstName.from( "AnotherClass name " ).should == "AnotherClassName"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|