Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
knlynda committed Dec 9, 2015
0 parents commit 5a932f1
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-r turnip/rspec
1 change: 1 addition & 0 deletions .ruby-gemset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
turnip_example
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-2.0.0-p353
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gem "turnip"
29 changes: 29 additions & 0 deletions Gemfile.lock
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
27 changes: 27 additions & 0 deletions lib/monster.rb
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
36 changes: 36 additions & 0 deletions lib/player.rb
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
17 changes: 17 additions & 0 deletions spec/acceptance/attack_monster.feature
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
22 changes: 22 additions & 0 deletions spec/spec_helper.rb
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
29 changes: 29 additions & 0 deletions spec/steps/attack_monster_steps.rb
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 }
4 changes: 4 additions & 0 deletions spec/steps/common_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Turnip::Steps

end

2 changes: 2 additions & 0 deletions spec/turnip_helper.rb
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 }

0 comments on commit 5a932f1

Please sign in to comment.