Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding initial cucumber feature

  • Loading branch information...
commit b839964958d7fe1b7cb13e7a4d4b68ed5327f43c 1 parent ad30bc5
@ryanb authored
View
16 features/profiles.feature
@@ -0,0 +1,16 @@
+Feature: Manage Profiles
+ In order play ruby warrior
+ As a player
+ I want to create and choose profiles
+
+ Background:
+ Given I have no profile
+
+ Scenario: New profile
+ When I run rubywarrior
+ And I answer "y" to "create one?"
+ And I answer "1" to "tower"
+ And I wait 1 second
+ And I answer "Joe" to "name"
+ Then I should see "generated"
+ And I should find file at "ruby-warrior"
View
48 features/step_definitions/interaction_steps.rb
@@ -0,0 +1,48 @@
+Given /^I have no profile$/ do
+ RubyWarrior::Config.path_prefix = "tmp"
+ FileUtils.rm_rf("tmp/ruby-warrior")
+end
+
+When /^I run rubywarrior$/ do
+ @io = MockIO.new
+ @io.start do |io|
+ RubyWarrior::UI.out_stream = io
+ RubyWarrior::UI.in_stream = io
+ RubyWarrior::Game.new.start
+ end
+end
+
+When /^I answer "([^\"]*)" to "([^\"]*)"$/ do |answer, question|
+ content = @io.gets
+ while !content.include?(question)
+ begin
+ content += @io.gets
+ rescue
+ raise "Unable to find #{question} in #{content}"
+ end
+ end
+ @io.puts(answer)
+end
+
+When /^I wait until it says "([^\"]*)"$/ do |saying|
+ content = @io.gets
+ while !content.include?(saying)
+ begin
+ content += @io.gets
+ rescue
+ raise "Unable to find #{saying} in #{content}"
+ end
+ end
+end
+
+When /^I wait 1 second$/ do
+ sleep 1
+end
+
+Then /^I should see "([^\"]*)"$/ do |saying|
+ @io.gets.should include(saying)
+end
+
+Then /^I should find file at "([^\"]*)"$/ do |path|
+ File.exist?("tmp/" + path).should be_true
+end
View
5 features/support/env.rb
@@ -0,0 +1,5 @@
+require 'cucumber'
+require 'spec'
+
+require File.dirname(__FILE__) + '/../../lib/ruby_warrior'
+
View
38 features/support/mockio.rb
@@ -0,0 +1,38 @@
+class MockIO
+ def initialize(receiver = nil)
+ @buffer = ""
+ @receiver = receiver || MockIO.new(self)
+ end
+
+ def gets
+ 1000.times do |n|
+ sleep 0.01 if n > 800 # throttle if it seems to be taking a while
+ unless @buffer.empty?
+ content = @buffer
+ @buffer = ""
+ return content
+ end
+ end
+ raise "MockIO Timeout: No content was received for gets."
+ end
+
+ # TODO make this thread safe
+ def puts(str)
+ @receiver << "#{str}\n"
+ end
+
+ def print(str)
+ @receiver << str.to_s
+ end
+
+ def <<(str)
+ @buffer << str
+ end
+
+ def start
+ Thread.abort_on_exception = true
+ @thread = Thread.new do
+ yield(@receiver)
+ end
+ end
+end
View
1  lib/ruby_warrior.rb
@@ -5,6 +5,7 @@
require 'ruby_warrior/game'
require 'ruby_warrior/profile'
require 'ruby_warrior/ui'
+require 'ruby_warrior/config'
require 'ruby_warrior/player_generator'
require 'ruby_warrior/level_loader'
require 'ruby_warrior/tower'
View
11 lib/ruby_warrior/config.rb
@@ -0,0 +1,11 @@
+module RubyWarrior
+ class Config
+ class << self
+ attr_writer :path_prefix
+
+ def path_prefix
+ @path_prefix || "."
+ end
+ end
+ end
+end
View
6 lib/ruby_warrior/game.rb
@@ -5,7 +5,7 @@ class Game
def start
UI.puts "Welcome to Ruby Warrior"
- make_game_directory unless File.exists?('ruby-warrior')
+ make_game_directory unless File.exists?(Config.path_prefix + '/ruby-warrior')
if current_level.number.zero?
prepare_next_level
@@ -38,7 +38,7 @@ def start
def make_game_directory
if UI.ask("No ruby-warrior directory found, would you like to create one?")
- Dir.mkdir('ruby-warrior')
+ Dir.mkdir(Config.path_prefix + '/ruby-warrior')
else
UI.puts "Unable to continue without directory."
exit
@@ -59,7 +59,7 @@ def profiles
end
def profile_paths
- Dir['ruby-warrior/**/.profile']
+ Dir[Config.path_prefix + '/ruby-warrior/**/.profile']
end
def profile
View
2  lib/ruby_warrior/profile.rb
@@ -29,7 +29,7 @@ def self.load(path)
end
def player_path
- "ruby-warrior/#{tower.name}-tower"
+ Config.path_prefix + "/ruby-warrior/#{tower.name}-tower"
end
def current_level_path
View
8 script/console
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+# File: script/console
+irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
+
+# loading the spec_helper file even though this isn't necessarily for specs
+# it's just a convenient, quick way to load all the requirements.
+puts "Loading console"
+exec "#{irb} -r irb/completion -r #{File.dirname(__FILE__) + '/../lib/ruby_warrior.rb'} -r #{File.dirname(__FILE__) + '/../features/support/mockio.rb'} --simple-prompt"
View
4 spec/ruby_warrior/game_spec.rb
@@ -9,7 +9,7 @@
it "should make game directory if player says so" do
RubyWarrior::UI.stubs(:ask).returns(true)
- Dir.expects(:mkdir).with('ruby-warrior')
+ Dir.expects(:mkdir).with('./ruby-warrior')
@game.make_game_directory
end
@@ -30,7 +30,7 @@
end
it "should find profile paths using Dir[] search" do
- Dir.expects(:[]).with("ruby-warrior/**/.profile")
+ Dir.expects(:[]).with("./ruby-warrior/**/.profile")
@game.profile_paths
end
View
4 spec/ruby_warrior/profile_spec.rb
@@ -75,11 +75,11 @@
end
it "should guess at the player path" do
- @profile.player_path.should == 'ruby-warrior/tower-tower'
+ @profile.player_path.should == './ruby-warrior/tower-tower'
end
it "should append level dir to player path" do
- @profile.current_level_path.should == 'ruby-warrior/tower-tower/level-000'
+ @profile.current_level_path.should == './ruby-warrior/tower-tower/level-000'
end
it "should load tower from path" do
Please sign in to comment.
Something went wrong with that request. Please try again.