-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5a932f1
Showing
13 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-r turnip/rspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
turnip_example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ruby-2.0.0-p353 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "turnip" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
diff-lcs (1.2.5) | ||
gherkin (2.12.2) | ||
multi_json (~> 1.3) | ||
multi_json (1.11.2) | ||
rspec (3.4.0) | ||
rspec-core (~> 3.4.0) | ||
rspec-expectations (~> 3.4.0) | ||
rspec-mocks (~> 3.4.0) | ||
rspec-core (3.4.1) | ||
rspec-support (~> 3.4.0) | ||
rspec-expectations (3.4.0) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.4.0) | ||
rspec-mocks (3.4.0) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.4.0) | ||
rspec-support (3.4.1) | ||
turnip (2.0.0) | ||
gherkin (>= 2.5) | ||
rspec (>= 3.0, < 4.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
turnip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class Monster | ||
attr_reader :hp, :armor, :damage, :live | ||
|
||
def initialize(hp=100, armor=3, damage=10) | ||
@hp = hp | ||
@armor = armor | ||
@damage = damage | ||
@live = true | ||
end | ||
|
||
def attack(someone) | ||
someone.get_damage(damage) | ||
end | ||
|
||
def get_damage(damage) | ||
if armor < damage | ||
@hp = hp + armor - damage | ||
@live = hp > 0 | ||
end | ||
|
||
hp | ||
end | ||
|
||
def live? | ||
live | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class Player | ||
attr_reader :hp, :armor, :damage, :live | ||
|
||
def initialize | ||
@hp = 100 | ||
@armor = 3 | ||
@damage = 10 | ||
@live = true | ||
end | ||
|
||
def attack(someone) | ||
someone.get_damage(damage) | ||
end | ||
|
||
def kill(someone) | ||
raise "I can not kill the #{someone.class}" if someone.armor > damage | ||
|
||
loop do | ||
break unless someone.live? | ||
someone.get_damage(damage) | ||
end | ||
end | ||
|
||
def get_damage(damage) | ||
if armor < damage | ||
@hp = hp + armor - damage | ||
@live = hp > 0 | ||
end | ||
|
||
hp | ||
end | ||
|
||
def live? | ||
live | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@attack_monster_steps | ||
Feature: Attacking a monster | ||
As player | ||
I want to attack monsters | ||
So I can attack and kill monsters | ||
|
||
Background: | ||
Given I am a player | ||
And there is a monster | ||
|
||
Scenario: attack the monster | ||
When I attack monster | ||
Then monster should not die | ||
|
||
Scenario: kill the monster | ||
When I kill monster | ||
Then monster should die |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'rspec' | ||
require 'monster' | ||
require 'player' | ||
|
||
RSpec.configure do |config| | ||
config.color = true | ||
|
||
config.before(:all) do | ||
end | ||
|
||
config.before(:type => :feature) do | ||
end | ||
|
||
config.after(:each) do | ||
end | ||
|
||
config.after(:suite) do | ||
end | ||
|
||
at_exit do | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module AttackMonsterSteps | ||
step 'I am a player' do | ||
@player = Player.new | ||
end | ||
|
||
step 'there is a monster' do | ||
@monster = Monster.new | ||
end | ||
|
||
|
||
step 'I attack monster' do | ||
@player.attack(@monster) | ||
end | ||
|
||
step 'I kill monster' do | ||
@player.kill(@monster) | ||
end | ||
|
||
|
||
step 'monster should die' do | ||
expect(@monster).to_not be_live | ||
end | ||
|
||
step 'monster should not die' do | ||
expect(@monster).to be_live | ||
end | ||
end | ||
|
||
RSpec.configure { |c| c.include AttackMonsterSteps, attack_monster_steps: true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Turnip::Steps | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'turnip' | ||
Dir.glob('spec/steps/**/*steps.rb') { |f| load f, true } |