cukesalad 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/Examples/Calculator/Gemfile +5 -0
- data/Examples/Calculator/Gemfile.lock +66 -0
- data/Examples/Calculator/cucumber.yml +4 -0
- data/Examples/Calculator/features/LOOK_MA_NO_STEP_DEFS.txt +2 -0
- data/Examples/Calculator/features/a_place_to_start.feature +9 -0
- data/Examples/Calculator/features/addition.feature +19 -0
- data/Examples/Calculator/features/complex_calculations.feature +16 -0
- data/Examples/Calculator/features/lib/alternative/roles/calculating_web_user.rb +55 -0
- data/Examples/Calculator/features/lib/default/roles/calculating_individual.rb +32 -0
- data/Examples/Calculator/features/lib/default/tasks/add.rb +13 -0
- data/Examples/Calculator/features/lib/default/tasks/calculate.rb +4 -0
- data/Examples/Calculator/features/lib/default/tasks/calculations.rb +15 -0
- data/Examples/Calculator/features/lib/default/tasks/see_the_answer.rb +3 -0
- data/Examples/Calculator/features/lib/default/tasks/subtract.rb +4 -0
- data/Examples/Calculator/features/lib/default/tasks/switch_on_the_calculator.rb +9 -0
- data/Examples/Calculator/features/subtraction.feature +20 -0
- data/Examples/Calculator/features/support/env.rb +6 -0
- data/Examples/Calculator/features/typical_workflow.feature +18 -0
- data/Examples/Calculator/lib/calculator.rb +53 -0
- data/Examples/Calculator/lib/config.ru +4 -0
- data/Examples/Calculator/lib/web_calculator.rb +82 -0
- data/Examples/Calculator/spec/calculator_spec.rb +73 -0
- data/Examples/Calculator/spec/web_calculator_spec.rb +99 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +47 -0
- data/LICENSE +21 -0
- data/README.md +273 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/bin/cukesalad +28 -0
- data/cucumber.yml +4 -0
- data/cukesalad/cli.rb +68 -0
- data/examples/Calculator/features/lib/alternative/roles/calculating_web_user.rb +55 -0
- data/examples/Calculator/features/lib/default/roles/calculating_individual.rb +32 -0
- data/examples/Calculator/features/lib/default/tasks/add.rb +13 -0
- data/examples/Calculator/features/lib/default/tasks/calculate.rb +4 -0
- data/examples/Calculator/features/lib/default/tasks/calculations.rb +15 -0
- data/examples/Calculator/features/lib/default/tasks/see_the_answer.rb +3 -0
- data/examples/Calculator/features/lib/default/tasks/subtract.rb +4 -0
- data/examples/Calculator/features/lib/default/tasks/switch_on_the_calculator.rb +9 -0
- data/examples/Calculator/features/support/env.rb +6 -0
- data/examples/Calculator/lib/calculator.rb +53 -0
- data/examples/Calculator/lib/web_calculator.rb +82 -0
- data/examples/Calculator/spec/calculator_spec.rb +73 -0
- data/examples/Calculator/spec/web_calculator_spec.rb +99 -0
- data/features/a_new_cukesalad_project.feature +34 -0
- data/features/define_a_role.feature +31 -0
- data/features/define_a_task.feature +55 -0
- data/features/lib/roles/step_free_cuker.rb +5 -0
- data/features/lib/tasks/create_a_file.rb +3 -0
- data/features/lib/tasks/create_a_new_cukesalad_project.rb +11 -0
- data/features/lib/tasks/create_a_role.rb +4 -0
- data/features/lib/tasks/create_a_task.rb +4 -0
- data/features/lib/tasks/create_directories.rb +5 -0
- data/features/lib/tasks/not_create_a_role.rb +2 -0
- data/features/lib/tasks/not_create_a_task.rb +3 -0
- data/features/lib/tasks/run.rb +4 -0
- data/features/lib/tasks/run_a_scenario.rb +7 -0
- data/features/lib/tasks/see_a_reply.rb +3 -0
- data/features/lib/tasks/see_the_step_has.rb +4 -0
- data/features/support/env.rb +7 -0
- data/lib/actor.rb +32 -0
- data/lib/codify/const_name.rb +21 -0
- data/lib/cukesalad.rb +33 -0
- data/lib/director.rb +28 -0
- data/lib/specifics.rb +30 -0
- data/lib/task_author.rb +12 -0
- data/spec/actor_spec.rb +72 -0
- data/spec/codify/as_const_name_spec.rb +28 -0
- data/spec/cukesalad/cli_spec.rb +99 -0
- data/spec/director_spec.rb +34 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/specifics_spec.rb +36 -0
- data/spec/task_author_spec.rb +50 -0
- metadata +202 -0
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
@@ -0,0 +1,66 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
builder (3.0.0)
|
5
|
+
capybara (0.4.1.2)
|
6
|
+
celerity (>= 0.7.9)
|
7
|
+
culerity (>= 0.2.4)
|
8
|
+
mime-types (>= 1.16)
|
9
|
+
nokogiri (>= 1.3.3)
|
10
|
+
rack (>= 1.0.0)
|
11
|
+
rack-test (>= 0.5.4)
|
12
|
+
selenium-webdriver (>= 0.0.27)
|
13
|
+
xpath (~> 0.1.3)
|
14
|
+
celerity (0.8.9)
|
15
|
+
childprocess (0.1.8)
|
16
|
+
ffi (~> 1.0.6)
|
17
|
+
cucumber (0.10.0)
|
18
|
+
builder (>= 2.1.2)
|
19
|
+
diff-lcs (~> 1.1.2)
|
20
|
+
gherkin (~> 2.3.2)
|
21
|
+
json (~> 1.4.6)
|
22
|
+
term-ansicolor (~> 1.0.5)
|
23
|
+
culerity (0.2.15)
|
24
|
+
diff-lcs (1.1.2)
|
25
|
+
ffi (1.0.7)
|
26
|
+
rake (>= 0.8.7)
|
27
|
+
gherkin (2.3.5)
|
28
|
+
json (>= 1.4.6)
|
29
|
+
json (1.4.6)
|
30
|
+
json_pure (1.5.1)
|
31
|
+
mime-types (1.16)
|
32
|
+
nokogiri (1.4.4)
|
33
|
+
rack (1.2.2)
|
34
|
+
rack-test (0.5.7)
|
35
|
+
rack (>= 1.0)
|
36
|
+
rake (0.8.7)
|
37
|
+
rspec (2.5.0)
|
38
|
+
rspec-core (~> 2.5.0)
|
39
|
+
rspec-expectations (~> 2.5.0)
|
40
|
+
rspec-mocks (~> 2.5.0)
|
41
|
+
rspec-core (2.5.1)
|
42
|
+
rspec-expectations (2.5.0)
|
43
|
+
diff-lcs (~> 1.1.2)
|
44
|
+
rspec-mocks (2.5.0)
|
45
|
+
rubyzip (0.9.4)
|
46
|
+
selenium-webdriver (0.1.4)
|
47
|
+
childprocess (>= 0.1.7)
|
48
|
+
ffi (>= 1.0.7)
|
49
|
+
json_pure
|
50
|
+
rubyzip
|
51
|
+
sinatra (1.2.0)
|
52
|
+
rack (~> 1.1)
|
53
|
+
tilt (< 2.0, >= 1.2.2)
|
54
|
+
term-ansicolor (1.0.5)
|
55
|
+
tilt (1.2.2)
|
56
|
+
xpath (0.1.3)
|
57
|
+
nokogiri (~> 1.3)
|
58
|
+
|
59
|
+
PLATFORMS
|
60
|
+
ruby
|
61
|
+
|
62
|
+
DEPENDENCIES
|
63
|
+
capybara (= 0.4.1.2)
|
64
|
+
cucumber (= 0.10.0)
|
65
|
+
rspec (= 2.5.0)
|
66
|
+
sinatra (= 1.2.0)
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Feature: A Place To Start
|
2
|
+
As Callie, a calculating individual
|
3
|
+
I want to know when my calculator is on
|
4
|
+
So that I know when I can start calculating
|
5
|
+
|
6
|
+
Scenario: Let's Begin
|
7
|
+
Given I am a Calculating Individual
|
8
|
+
When I attempt to switch on the calculator
|
9
|
+
Then I should see the answer '0'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Feature: Addition
|
2
|
+
As Callie, a calculating individual
|
3
|
+
I want to quickly find out the sum of some numbers
|
4
|
+
So that I am not tired out by doing mental arithmetic all day
|
5
|
+
|
6
|
+
Scenario Outline: Find the sum of two numbers
|
7
|
+
Given I am a Calculating Individual
|
8
|
+
And I was able to switch on the calculator
|
9
|
+
When I attempt to add: the number '<first_number>' to the number '<second_number>'
|
10
|
+
Then I should see the answer '<result>'
|
11
|
+
|
12
|
+
|
13
|
+
Examples:
|
14
|
+
|first_number|second_number|result|
|
15
|
+
| 0 | 0 | 0 |
|
16
|
+
| 0 | 1 | 1 |
|
17
|
+
| 1 | 0 | 1 |
|
18
|
+
| 1 | 1 | 2 |
|
19
|
+
| 10 | 9 | 19 |
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Feature: Complex Calculations
|
2
|
+
As Callie, a calculating individual
|
3
|
+
I want to do more complicated calculations
|
4
|
+
So that I am not tired out by doing mental arithmetic all day
|
5
|
+
|
6
|
+
Scenario Outline: Get the result of a more complex calculation
|
7
|
+
Given I am a calculating individual
|
8
|
+
And I was able to switch on the calculator
|
9
|
+
When I attempt to calculate: with the following '<calculation>'
|
10
|
+
Then I should see the answer '<correct_result>'
|
11
|
+
|
12
|
+
Examples:
|
13
|
+
| calculation | correct_result |
|
14
|
+
| 1 + 1 + 1 = | 3 |
|
15
|
+
| 10 + 5 - 3 = | 12 |
|
16
|
+
| 10 + 5 - 3 - 12 = | 0 |
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# To run with this version of the Calculating Individual:
|
2
|
+
# cucumber --profile alternative
|
3
|
+
|
4
|
+
require 'web_calculator'
|
5
|
+
require 'capybara'
|
6
|
+
require 'capybara/dsl'
|
7
|
+
|
8
|
+
Capybara.app = WebCalculator
|
9
|
+
Capybara.default_driver = :rack_test
|
10
|
+
|
11
|
+
module CalculatingIndividual
|
12
|
+
|
13
|
+
# Uses a Browser to perform its tasks
|
14
|
+
include Capybara
|
15
|
+
# This is not a page object. It is a WebUser, specialised to our application
|
16
|
+
# See the comments in the 'enter' and 'press' method for an explanation of why
|
17
|
+
|
18
|
+
def switch_on_the_calculator
|
19
|
+
visit '/'
|
20
|
+
end
|
21
|
+
|
22
|
+
def enter value
|
23
|
+
fill_in 'number', :with => value
|
24
|
+
# Because the calculator is a simple web_app with only
|
25
|
+
# one page we can put the id for the field here. In a more complex web-app
|
26
|
+
# we would pass in the id of the thing to enter
|
27
|
+
# The task would express the action as: enter( :the_number, "10")
|
28
|
+
# Because we can change the id used in our application,
|
29
|
+
# we would just change the id in the application to be 'the_number'.
|
30
|
+
# If we were on a project where we could not change the id
|
31
|
+
# in the application we would write an 'ApplicationExpert'
|
32
|
+
# to map :the_number to the id for the field 'number'. Our CalculatingIndividual
|
33
|
+
# would ask the ApplicationExpert for the id of the symbol :the_number
|
34
|
+
# See 'press' below for am explanation of how an ApplicationExpert
|
35
|
+
# would work
|
36
|
+
end
|
37
|
+
|
38
|
+
def press operator
|
39
|
+
click_button operator.to_s
|
40
|
+
# Here, our 'operator' happens to also match the id for the button.
|
41
|
+
# If we were on a project where we could not choose what the id
|
42
|
+
# was for buttons, we would write an ApplicationExpert to map
|
43
|
+
# the symbol used in the task to the symbol for that button.
|
44
|
+
# The ApplicationExpert would only need to know what page it
|
45
|
+
# was on to find a mappings class (or yml file) for the fields on that page.
|
46
|
+
end
|
47
|
+
|
48
|
+
def look_at_the_display
|
49
|
+
find_field('display').value.to_i
|
50
|
+
end
|
51
|
+
|
52
|
+
def is_the_calculator_ready?
|
53
|
+
page.body.should =~ /Calculator is Ready!/
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'calculator'
|
2
|
+
|
3
|
+
module CalculatingIndividual
|
4
|
+
|
5
|
+
def switch_on_the_calculator
|
6
|
+
@calculator = Calculator.new
|
7
|
+
@operate_with = {
|
8
|
+
plus: :+,
|
9
|
+
minus: :-
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def enter value
|
14
|
+
@calculator.enter value.to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
def press next_operator
|
18
|
+
if next_operator == :equals
|
19
|
+
equals
|
20
|
+
else
|
21
|
+
@calculator.get_ready_to @operate_with[next_operator]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def equals
|
26
|
+
@calculator.equals
|
27
|
+
end
|
28
|
+
|
29
|
+
def look_at_the_display
|
30
|
+
@calculator.display
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# This demonstrates how to use an attribute mapping
|
2
|
+
# to make the interactions within the task read more naturally
|
3
|
+
# In the scenario it might say "add: the number '5', to the number '10'
|
4
|
+
# The form illustrated below simply maps the elements the_number and to_the_number
|
5
|
+
# to alternative symbols that make the interactions read more like real instructions
|
6
|
+
# See subtract.rb for a way of writing tasks that reuses the common interactions
|
7
|
+
# required to perform calculations.
|
8
|
+
in_order_to 'add', the_number: :first_number, to_the_number: :second_number do
|
9
|
+
enter the :first_number
|
10
|
+
press :plus
|
11
|
+
enter the :second_number
|
12
|
+
press :equals
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Calculations
|
2
|
+
|
3
|
+
def follow_the_steps_for sum
|
4
|
+
enter_numbers_and_operators_for sum
|
5
|
+
end
|
6
|
+
|
7
|
+
def enter_numbers_and_operators_for sum
|
8
|
+
operator = {"+" => :plus, "-" => :minus, "=" => :equals}
|
9
|
+
sum.each do | token |
|
10
|
+
enter token.to_i if token =~ /\d+/
|
11
|
+
press operator[token] if operator.include? token
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Feature: Subtraction
|
2
|
+
As Callie, a calculating individual
|
3
|
+
I want to quickly find the difference between two numbers
|
4
|
+
So that I am not tired out by doing mental arithmetic all day
|
5
|
+
|
6
|
+
Scenario Outline: Find the result of subtracting two numbers
|
7
|
+
Given I am a Calculating Individual
|
8
|
+
And I was able to switch on the calculator
|
9
|
+
When I attempt to subtract: the number '<subtractor>' from the number '<subtractee>'
|
10
|
+
Then I should see the answer '<result>'
|
11
|
+
|
12
|
+
|
13
|
+
Examples:
|
14
|
+
| subtractor | subtractee | result|
|
15
|
+
| 0 | 0 | 0 |
|
16
|
+
| 0 | 1 | 1 |
|
17
|
+
| 1 | 1 | 0 |
|
18
|
+
| 5 | 10 | 5 |
|
19
|
+
|
20
|
+
|
@@ -0,0 +1,6 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../../lib') #where to find the calculator implementation
|
2
|
+
$:.unshift(File.dirname(__FILE__) + '/../../../../lib') #where to find CukeSalad
|
3
|
+
|
4
|
+
require 'cukesalad'
|
5
|
+
|
6
|
+
begin require 'rspec/expectations'; rescue LoadError; require 'spec/expectations'; end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Feature: Typical Calculator Workflow
|
2
|
+
As Callie, a calculating individual
|
3
|
+
I want to interact with this calculator like any other calculator
|
4
|
+
So that I can start using it straight away
|
5
|
+
|
6
|
+
Scenario Outline: See what I expect based on specific interactions
|
7
|
+
Given I am a calculating individual
|
8
|
+
And I was able to switch on the calculator
|
9
|
+
When I attempt to calculate: with the following '<interactions>'
|
10
|
+
Then I should see the answer '<expected>'
|
11
|
+
|
12
|
+
Examples:
|
13
|
+
| interactions | expected |
|
14
|
+
| 1 = | 1 |
|
15
|
+
| 1 + = | 2 |
|
16
|
+
| 1 - = | 0 |
|
17
|
+
| 1 + = = | 3 |
|
18
|
+
| 1 + 1 = 5 + = | 10 |
|
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
class Calculator
|
3
|
+
|
4
|
+
attr_reader :display
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
show 0
|
8
|
+
@operands = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def enter value
|
12
|
+
show value
|
13
|
+
@operands.push value
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_ready_to op
|
17
|
+
calculate_if_necessary
|
18
|
+
start_next_calculation
|
19
|
+
@operator = op
|
20
|
+
end
|
21
|
+
|
22
|
+
def equals
|
23
|
+
we_need_two_operands
|
24
|
+
deal_with_repeated_equals
|
25
|
+
unless @operator.nil?
|
26
|
+
show @operands.inject (@operator)
|
27
|
+
@last_operator = @operator
|
28
|
+
@operator = nil
|
29
|
+
@operands[0] = @display
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def show value
|
35
|
+
@display = value
|
36
|
+
end
|
37
|
+
|
38
|
+
def calculate_if_necessary
|
39
|
+
equals if @operands.size == 2
|
40
|
+
end
|
41
|
+
|
42
|
+
def start_next_calculation
|
43
|
+
@operands = [@display] if @operator.nil?
|
44
|
+
end
|
45
|
+
|
46
|
+
def we_need_two_operands
|
47
|
+
@operands.concat @operands if @operands.size == 1
|
48
|
+
end
|
49
|
+
|
50
|
+
def deal_with_repeated_equals
|
51
|
+
@operator = @last_operator if @operands.size == 2 && @operator.nil? && @last_operator
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'erb'
|
3
|
+
$:.unshift(File.dirname(__FILE__), '.')
|
4
|
+
require 'calculator'
|
5
|
+
|
6
|
+
Sinatra::Base.enable :inline_templates
|
7
|
+
Sinatra::Base.enable :sessions
|
8
|
+
|
9
|
+
class WebCalculator < Sinatra::Base
|
10
|
+
|
11
|
+
helpers do
|
12
|
+
def operate_with
|
13
|
+
{ 'plus' => :+, 'minus' => :-}
|
14
|
+
end
|
15
|
+
|
16
|
+
def persist calc
|
17
|
+
session[:calc] = calc
|
18
|
+
end
|
19
|
+
|
20
|
+
def display_result_from calc
|
21
|
+
@display = calc.display
|
22
|
+
erb :index
|
23
|
+
end
|
24
|
+
|
25
|
+
def user_input
|
26
|
+
params[:number].to_i
|
27
|
+
end
|
28
|
+
|
29
|
+
def selected_operator
|
30
|
+
params[:operator]
|
31
|
+
end
|
32
|
+
|
33
|
+
def display_result_from_session
|
34
|
+
@display = session[:calc].display ||= 0
|
35
|
+
erb :index
|
36
|
+
end
|
37
|
+
|
38
|
+
def input_entered?
|
39
|
+
not params[:number].empty?
|
40
|
+
end
|
41
|
+
|
42
|
+
def equals_pressed?
|
43
|
+
selected_operator == "equals"
|
44
|
+
end
|
45
|
+
|
46
|
+
def load_calculator
|
47
|
+
session[:calc] ||= Calculator.new
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
get '/' do
|
53
|
+
load_calculator
|
54
|
+
display_result_from_session
|
55
|
+
end
|
56
|
+
|
57
|
+
post '/' do
|
58
|
+
calculator = load_calculator
|
59
|
+
calculator.enter user_input if input_entered?
|
60
|
+
if equals_pressed?
|
61
|
+
calculator.equals
|
62
|
+
else
|
63
|
+
calculator.get_ready_to operate_with[selected_operator]
|
64
|
+
end
|
65
|
+
persist calculator
|
66
|
+
display_result_from calculator
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
__END__
|
71
|
+
@@ layout
|
72
|
+
<h1>Calculator is Ready!</h1>
|
73
|
+
<%= yield %>
|
74
|
+
|
75
|
+
@@ index
|
76
|
+
<form method="POST" action="/">
|
77
|
+
<input type="text" disabled name="display" id="display" value="<%=@display %>" />
|
78
|
+
<input type="text" name="number" id="number" />
|
79
|
+
<input type="submit" name="operator" id="minus" text="-" value="minus" />
|
80
|
+
<input type="submit" name="operator" id="plus" text="+" value="plus" />
|
81
|
+
<input type="submit" name="operator" id="equals" text="=" value="equals" />
|
82
|
+
</form>
|
@@ -0,0 +1,73 @@
|
|
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
|
@@ -0,0 +1,99 @@
|
|
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
|