Skip to content

Commit

Permalink
Merge pull request #2 from esambo/master
Browse files Browse the repository at this point in the history
Awesome, thanks! RSpec 2 support
  • Loading branch information
coreyhaines committed Nov 25, 2011
2 parents feb5e96 + 3134f87 commit f104ad0
Show file tree
Hide file tree
Showing 21 changed files with 225 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
coverage
rdoc
pkg
rerun.txt
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--format documentation
32 changes: 32 additions & 0 deletions .rvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
# Based on: http://rvm.beginrescueend.com/workflow/rvmrc/

ruby_string="ruby-1.9.3-p0"
gemset_name="practice_game_of_life"

if rvm list strings | grep -q "${ruby_string}" ; then

# Load or create the specified environment
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
&& -s "${rvm_path:-$HOME/.rvm}/environments/${ruby_string}@${gemset_name}" ]] ; then
\. "${rvm_path:-$HOME/.rvm}/environments/${ruby_string}@${gemset_name}"
else
rvm --create "${ruby_string}@${gemset_name}"
fi

(
# Ensure that Bundler is installed, install it if it is not.
if ! command -v bundle ; then
gem install bundler
fi

# Bundle while redcing excess noise.
bundle | grep -v 'Using' | grep -v 'complete' | sed '/^$/d'
)&

else

# Notify the user to install the desired interpreter before proceeding.
echo "${ruby_string} was not found, please run 'rvm install ${ruby_string}' and then cd back into the project directory."

fi
12 changes: 12 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
source :rubygems
gem 'rake'
gem 'jeweler'
gem 'rdoc'
gem 'rcov'
gem 'relish'

gem 'rspec'
gem 'cucumber'
gem 'guard-rspec'
gem 'guard-cucumber'
gem 'growl_notify'
66 changes: 66 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
GEM
remote: http://rubygems.org/
specs:
archive-tar-minitar (0.5.2)
builder (3.0.0)
cucumber (1.0.0)
builder (>= 2.1.2)
diff-lcs (>= 1.1.2)
gherkin (~> 2.4.1)
json (>= 1.4.6)
term-ansicolor (>= 1.0.5)
diff-lcs (1.1.2)
gherkin (2.4.1)
json (>= 1.4.6)
git (1.2.5)
growl_notify (0.0.1)
rb-appscript
guard (0.6.3)
thor (~> 0.14.6)
guard-cucumber (0.6.2)
cucumber (>= 0.10)
guard (>= 0.4.0)
guard-rspec (0.4.4)
guard (>= 0.4.0)
jeweler (1.6.4)
bundler (~> 1.0)
git (>= 1.2.5)
rake
json (1.5.3)
mime-types (1.17.2)
rake (0.9.2.2)
rb-appscript (0.6.1)
rcov (0.9.11)
rdoc (3.11)
json (~> 1.4)
relish (0.5.3)
archive-tar-minitar (>= 0.5.2)
json (>= 1.4.6)
rest-client (>= 1.6.1)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec (2.6.0)
rspec-core (~> 2.6.0)
rspec-expectations (~> 2.6.0)
rspec-mocks (~> 2.6.0)
rspec-core (2.6.4)
rspec-expectations (2.6.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.6.0)
term-ansicolor (1.0.5)
thor (0.14.6)

PLATFORMS
ruby

DEPENDENCIES
cucumber
growl_notify
guard-cucumber
guard-rspec
jeweler
rake
rcov
rdoc
relish
rspec
11 changes: 11 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
guard 'rspec', version: 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec/" }
end

guard 'cucumber', cli: '--profile guard' do
watch(%r{^features/.+\.feature$})
watch(%r{^features/support/.+$}) { 'features' }
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
end
26 changes: 13 additions & 13 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,35 @@ rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end

require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:spec) do |spec|
spec.libs << 'lib' << 'spec'
spec.spec_files = FileList['spec/**/*_spec.rb']
require 'rspec'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.rspec_opts = ['--format doc', '--color']
end

Spec::Rake::SpecTask.new(:rcov) do |spec|
spec.libs << 'lib' << 'spec'
RSpec::Core::RakeTask.new(:rcov) do |spec|
spec.pattern = 'spec/**/*_spec.rb'
spec.rcov = true
end

task :spec => :check_dependencies
# task :spec => :check_dependencies

begin
require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:features)

task :features => :check_dependencies
Cucumber::Rake::Task.new(:features) do |f|
f.cucumber_opts = "features --format pretty"
# task :features => :check_dependencies
end
rescue LoadError
task :features do
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
end
end

task :default => :spec
task :default => [:spec, :cucumber]

require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
require 'rdoc/task'
RDoc::Task.new do |rdoc|
if File.exist?('VERSION')
version = File.read('VERSION')
else
Expand Down
2 changes: 2 additions & 0 deletions cucumber.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
wip: --tags @wip:3 --wip features
guard: --tags @wip --format progress --wip features
9 changes: 9 additions & 0 deletions features/.nav
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- doc (Documentation):
- rules_of_life.md (Rules of Life)
- rules_of_simple_design.md (Rules of Simple Design)
- source_code.md (Source Code)
- live_cell.feature
- dead_cell.feature
- multiple_cells.feature
- static_structures.feature
- multiple_generations.feature
20 changes: 20 additions & 0 deletions features/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Practice Game of Life

## [Code Retreat](http://coderetreat.com)
w/ [Corey Haines](http://www.twitter.com/coreyhaines)
*- honing the craft together*

Coderetreat is a day-long, intensive practice event, focusing on the fundamentals of software development and modular design, primarily the [4 Rules of Simple Design](http://c2.com/cgi/wiki?XpSimplicityRules):

1. Tests Pass (green)
2. Reveal Intent (good names)
3. No Duplication (DRY)
4. Small


## Wikipedia: [Conway's Game of Life](http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)

The **Game of Life**, also known simply as **Life**, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.

The "game" is a zero-player game, meaning that its evolution is determined by its initial state, requiring no further input. One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

6 changes: 3 additions & 3 deletions features/dead_cell.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: Evolving a dead cell
In order to create a functioning rules engine
As a programmer of Conway's Game of Life
I can evolve a single dead cell based
In order to create a functioning rules engine
As a programmer of Conway's Game of Life
I can evolve a single dead cell based

Scenario: Dead cell with 0 neighbors stays dead
Given the following setup
Expand Down
18 changes: 18 additions & 0 deletions features/doc/rules_of_life.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Based on Wikipedia: Conway's Game of Life: [Rules](http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life#Rules)

The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square *cells*, each of which is in one of two possible states, *alive* or *dead*. Every cell interacts with its eight *neighbors*, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:

### 1. Under-Population
- Any live cell with *fewer than 2* live neighbors *dies*

### 2. Next Generation
- Any live cell with *2 or 3* live neighbors *lives* on

### 3. Overcrowding
- Any live cell with *more than 3* live neighbors *dies*

### 4. Reproduction
- Any dead cell with *exactly 3* live neighbors becomes a *live* cell

The initial pattern constitutes the *seed* of the system. The first generation is created by applying the above rules simultaneously to every cell in the seed—births and deaths occur simultaneously, and the discrete moment at which this happens is sometimes called a *tick* (in other words, each generation is a pure function of the preceding one). The rules continue to be applied repeatedly to create further generations.

8 changes: 8 additions & 0 deletions features/doc/rules_of_simple_design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[4 Rules of Simple Design](http://c2.com/cgi/wiki?XpSimplicityRules):

Based on the [SCNA 2011 Code Retreat](http://twitpic.com/7gz0k2)

1. Tests Pass (green)
2. Reveal Intent (good names)
3. No Duplication (DRY)
4. Small
3 changes: 3 additions & 0 deletions features/doc/source_code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## [Cucumber Features](http://cukes.info/)
Building a Conways’ Game of Life simulator is a great way to practice different techniques in the language of your choice. This ***[git repository](https://github.com/coreyhaines/practice_game_of_life)*** contains a set of cucumber features that describe the rules of Conway’s Game of Life. I’ve also included a few standard, larger patterns that you can use to check multiple generation evolution.

6 changes: 3 additions & 3 deletions features/live_cell.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: Evolving a living cell
In order to create a functioning rules engine
As a programmer of Conway's Game of Life
I can evolve a single living cell
In order to create a functioning rules engine
As a programmer of Conway's Game of Life
I can evolve a single living cell

Scenario: Living cell with 0 neighbors dies
Given the following setup
Expand Down
6 changes: 3 additions & 3 deletions features/multiple_cells.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: Evolving a grid with some cells in it
In order to create a functioning rules engine
As a programmer of Conway's Game of Life
I can evolve a multiple cell grid
In order to create a functioning rules engine
As a programmer of Conway's Game of Life
I can evolve a multiple cell grid

Scenario: Sparse grid with nobody staying alive
Given the following setup
Expand Down
7 changes: 3 additions & 4 deletions features/multiple_generations.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: Evolving a grid over multiple generations
In order to create a functioning rules engine
As a programmer of Conway's Game of Life
I can evolve a grid over multiple generations
In order to create a functioning rules engine
As a programmer of Conway's Game of Life
I can evolve a grid over multiple generations

Scenario: Cells come alive, then die off
Given the following setup
Expand All @@ -24,4 +24,3 @@ Feature: Evolving a grid over multiple generations
| . | x | x | x | . |
| . | . | . | . | . |
| . | . | . | . | . |

6 changes: 3 additions & 3 deletions features/static_structures.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: Cell configurations that are static
In order to create a functioning rules engine
As a programmer of Conway's Game of Life
I can see static structures surviving in my world
In order to create a functioning rules engine
As a programmer of Conway's Game of Life
I can see static structures surviving in my world

Scenario: Block
Given the following setup
Expand Down
2 changes: 1 addition & 1 deletion features/support/env.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
require 'game_of_life'

require 'spec/expectations'
require 'rspec/expectations'
2 changes: 1 addition & 1 deletion spec/game_of_life_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'spec_helper'

describe "GameOfLife" do
it "fails" do
Expand Down
15 changes: 11 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'game_of_life'
require 'spec'
require 'spec/autorun'

Spec::Runner.configure do |config|
require 'rspec'
require 'rspec/autorun'

RSpec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec
end

0 comments on commit f104ad0

Please sign in to comment.