Skip to content

Commit

Permalink
Initial feature to check the files are generated in one case
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashley Moran committed Feb 9, 2010
1 parent 3e67ca7 commit 661872d
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Manifest
pkg
doc
doc
tmp
21 changes: 21 additions & 0 deletions features/descriptions/skeleton.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: cucumber:skeleton
In order to quickly set up Cucumber
As a Rails developer
I want to have the Cucumber skeleton generate automatically

Scenario: Rails 2 with Capybara
Given I'm using Ruby 1.8.7 and Rails 2.3.5
And a Rails app "rails-2-app"
When I run "script/generate cucumber --capybara" in the app
Then I will have the following new files and directories
| name |
| config/cucumber.yml |
| config/environments/cucumber.rb |
| script/cucumber |
| features/step_definitions |
| features/step_definitions/web_steps.rb |
| features/support |
| features/support/env.rb |
| features/support/paths.rb |
| lib/tasks |
| lib/tasks/cucumber.rake |
30 changes: 30 additions & 0 deletions features/step_definitions/cucumber_rails_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# TODO ~/.bash_profile

Given /^I'm using Ruby (.*) and Rails (.*)$/ do |ruby_version, rails_version|
@commands = Commands.new(ruby_version, rails_version)
end

Given /^a Rails app "(.*)"$/ do |app_name|
@rails_app = @commands.new_rails_app(app_name)
end

When /^I run "script\/(.*)" in the app$/ do |command|
@rails_app.script(command)
end

Spec::Matchers.define :have_files do |expected_files|
match do |rails_app|
actual_files = rails_app.files
@missing_files = expected_files - actual_files
@missing_files.empty?
end

failure_message_for_should do |expected_files|
"Rails app was missing these files:\n" + @missing_files.map { |file| " #{file}" }.join("\n")
end
end

Then /^I will have the following new files and directories$/ do |table|
expected_files = table.hashes.collect { |row| row[:name] }
@rails_app.should have_files(expected_files)
end
23 changes: 23 additions & 0 deletions features/support/commands.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Commands
def initialize(ruby_version, rails_version)
@ruby_version = ruby_version
check_version("Ruby", @ruby_version, %w[ 1.8.7 1.9.1 ])

@rails_version = rails_version
check_version("Rails", @rails_version, %w[ 2.3.5 ])

@runner = Runner.new("tmp", @ruby_version, @rails_version)
end

def new_rails_app(app_name)
@runner.rails("#{app_name}")
runner = Runner.new("tmp/#{app_name}", @ruby_version, @rails_version)
RailsApp.new(app_name, @rails_version, runner)
end

private

def check_version(command, version, allowed_versions)
raise %Q{Invalid #{command} version "#{version}"} unless allowed_versions.include?(version)
end
end
17 changes: 17 additions & 0 deletions features/support/commands/rails_app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Commands
class RailsApp
def initialize(app_name, rails_version, runner)
@app_name = app_name
@rails_version = rails_version
@runner = runner
end

def script(options)
@runner.rvm("script/#{options}")
end

def files
@runner.files
end
end
end
41 changes: 41 additions & 0 deletions features/support/commands/runner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Commands
class Runner
attr_reader :command_history

def initialize(directory, ruby_version, rails_version)
@directory = directory
@ruby_version = ruby_version
@rails_version = rails_version
@command_history = []
end

def rails(options)
rvm("rails _#{@rails_version}_ #{options}")
end

def rvm(command)
run_and_log("rvm #{@ruby_version} -S #{command}")
end

def files
in_runner_dir do
Dir["**/*"]
end
end

private

def run_and_log(command)
in_runner_dir do
@command_history << command
`#{command}`
end
end

def in_runner_dir
Dir.chdir(@directory) do
yield
end
end
end
end
9 changes: 9 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'rubygems'

gem 'rspec', '1.3.0'
require 'spec'

Before do
Dir.mkdir("tmp") unless Dir.exist?("tmp")
system "rm -rf tmp/*"
end
6 changes: 6 additions & 0 deletions features/support/gemfiles/ruby_187_rails_2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# TODO use this to set up the rvm environments
# gem "bundler"
gem "rails", "2.3.5"
gem "cucumber-rails"
gem "capybara"
gem "webrat"

0 comments on commit 661872d

Please sign in to comment.