Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleanup example for step reuse

  • Loading branch information...
commit a91e0639dbf5a618a933e5058d66284e9c8914f8 1 parent ab28cd7
@leshill leshill authored
View
43 README.md
@@ -168,11 +168,13 @@ and
### Reusing steps
When using scoped steps in Turnip, you can tell it to also include steps
-defined in another `steps_for` block. The syntax for that is `uses_steps`:
+defined in another `steps_for` block. The syntax for that is `use_steps`:
``` ruby
# dragon_steps.rb
steps_for :dragon do
+ use_steps :knight
+
attr_accessor :dragon
def dragon_attack
@@ -183,8 +185,8 @@ steps_for :dragon do
self.dragon = 1
end
- step "the dragon attacks for :count hitpoints" do |count|
- dragon_attack.should eq(count)
+ step "the dragon attacks the knight" do
+ knight.attacked_for(dragon_attack)
end
end
@@ -197,23 +199,44 @@ steps_for :red_dragon do
def dragon_attack
attack = super
if red_dragon
- attack + 10
+ attack + 15
else
attack
end
end
- step "it is a fire breathing red dragon" do
+ step "the dragon breathes fire" do
self.red_dragon = 1
end
end
```
-Notice in this example we are making full use of Ruby's modules including
-using super to call the included module's version of `dragon_attack`.
+
+In this example we are making full use of Ruby's modules including using super
+to call the included module's version of `dragon_attack`, for example with the
+following feature file:
+
+``` cucumber
+Feature: Red Dragons are deadly
+
+ @dragon
+ Scenario:
+ Given there is a dragon
+ And there is a knight
+ When the dragon attacks the knight
+ Then the knight is alive
+
+ @red_dragon
+ Scenario:
+ Given there is a dragon
+ And the dragon breathes fire
+ And there is a knight
+ When the dragon attacks the knight
+ Then the knight is dead
+```
### Auto-included steps
-By default, Turnip will automatically make available any steps defined in
+By default, Turnip will automatically make available any steps defined in
a `steps_for` block with the same name as the feature file being run. For
example, given this step file:
@@ -223,11 +246,11 @@ steps_for :user_signup do
step "I am on the homepage" do
...
end
-
+
step "I signup with valid info" do
...
end
-
+
step "I should see a welcome message" do
end
end
View
6 examples/dragon_steps.rb
@@ -1,4 +1,6 @@
steps_for :dragon do
+ use_steps :knight
+
attr_accessor :dragon
def dragon_attack
@@ -9,7 +11,7 @@ def dragon_attack
self.dragon = 1
end
- step "the dragon attacks for :count hitpoints" do |count|
- dragon_attack.should eq(count)
+ step "the dragon attacks the knight" do
+ knight.attacked_for(dragon_attack)
end
end
View
29 examples/knight_steps.rb
@@ -0,0 +1,29 @@
+steps_for :knight do
+ attr_accessor :knight
+
+ class Knight
+ def initialize
+ @hp = 20
+ end
+
+ def alive?
+ @hp > 0
+ end
+
+ def attacked_for(amount)
+ @hp -= amount
+ end
+ end
+
+ step "there is a knight" do
+ self.knight = Knight.new
+ end
+
+ step "the knight is alive" do
+ knight.should be_alive
+ end
+
+ step "the knight is dead" do
+ knight.should_not be_alive
+ end
+end
View
5 examples/red_dragon_steps.rb
@@ -6,14 +6,13 @@
def dragon_attack
attack = super
if red_dragon
- attack + 10
+ attack + 15
else
attack
end
end
- step "it is a fire breathing red dragon" do
+ step "the dragon breathes fire" do
self.red_dragon = 1
end
end
-
View
13 examples/steps_for_super.feature
@@ -1,11 +1,16 @@
-Feature: Tagged steps for and super
+Feature: Red Dragons are deadly
+
@dragon
Scenario:
Given there is a dragon
- Then the dragon attacks for 10 hitpoints
+ And there is a knight
+ When the dragon attacks the knight
+ Then the knight is alive
@red_dragon
Scenario:
Given there is a dragon
- And it is a fire breathing red dragon
- Then the dragon attacks for 20 hitpoints
+ And the dragon breathes fire
+ And there is a knight
+ When the dragon attacks the knight
+ Then the knight is dead
Please sign in to comment.
Something went wrong with that request. Please try again.