Permalink
Browse files

Basic acceptance spec creation

  • Loading branch information...
cavalle committed Mar 13, 2011
1 parent db72361 commit 8ab298ca657b483cfa33ef85dfab4d8bb591dbc4
View
@@ -2,3 +2,4 @@ source "http://rubygems.org"
gemspec
gem 'capybara', :git => 'git://github.com/jnicklas/capybara.git'
+gem 'ruby-debug'
View
@@ -50,13 +50,15 @@ GEM
builder (2.1.2)
childprocess (0.1.7)
ffi (~> 0.6.3)
+ columnize (0.3.1)
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
ffi (0.6.3)
rake (>= 0.8.7)
i18n (0.5.0)
json_pure (1.5.1)
+ linecache (0.43)
mail (2.2.15)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
@@ -97,12 +99,18 @@ GEM
activesupport (~> 3.0)
railties (~> 3.0)
rspec (~> 2.5.0)
+ ruby-debug (0.10.3)
+ columnize (>= 0.1)
+ ruby-debug-base (~> 0.10.3.0)
+ ruby-debug-base (0.10.3)
+ linecache (>= 0.3)
rubyzip (0.9.4)
selenium-webdriver (0.1.3)
childprocess (~> 0.1.5)
ffi (~> 0.6.3)
json_pure
rubyzip
+ sqlite3 (1.3.3)
thor (0.14.6)
treetop (1.4.9)
polyglot (>= 0.3.1)
@@ -117,4 +125,6 @@ DEPENDENCIES
capybara!
rails (>= 3.0.0)
rspec-rails (>= 2.5.0)
+ ruby-debug
+ sqlite3
steak!
@@ -0,0 +1,11 @@
+module Steak
+ module Generators
+ class SpecGenerator < Rails::Generators::NamedBase
+ source_root File.join(File.dirname(__FILE__), 'templates')
+
+ def main
+ template 'acceptance_spec.rb', File.join('spec/acceptance', "#{file_name}_spec.rb")
+ end
+ end
+ end
+end
@@ -0,0 +1,13 @@
+require 'spec_helper'
+
+feature '<%= human_name %>', %q{
+ In order to ...
+ As a ...
+ I want ...
+} do
+
+ scenario 'first scenario' do
+ true.should == true
+ end
+
+end
View
@@ -1 +1 @@
-# Your code goes here...
+require 'capybara/rspec'
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+feature 'Creating acceptance specs', %q{
+ In order to not having to do it manually
+ As a lazy Rails developer
+ I want empty new specs to be generated for me
+} do
+
+ scenario 'using the spec generator' do
+ generate_rails_project_with_steak
+
+ run 'rails g steak:spec my_first_feature'
+
+ path('spec/acceptance/my_first_feature_spec.rb').should exist
+ content_of('spec/acceptance/my_first_feature_spec.rb').should include("feature 'My first feature'")
+
+ run 'rspec spec/acceptance/my_first_feature_spec.rb'
+
+ output.should =~ /1 example, 0 failures/
+ end
+
+end
View
@@ -1,30 +1,59 @@
require 'tempfile'
module Helpers
+ attr_accessor :output
+
def generate_rails_project
- FileUtils.rm_rf rails_project_path
- run "rails new #{rails_project_path} -OG"
- silence_warnings { Dir.chdir rails_project_path }
+ rm_rf rails_project_path
+ cd # go to an existing dir
+ run "rails new #{rails_project_path}"
+ cd rails_project_path
+ end
+
+ def generate_rails_project_with_steak
+ generate_rails_project
+
+ append_to 'Gemfile', <<-RUBY
+ group(:test) do
+ gem 'steak', :path => '#{root_path}'
+ gem 'capybara', :path => '#{Bundler.load.specs['capybara'].first.full_gem_path}' # Totally temporal. It should be a steak dependency
+ end
+ RUBY
+
+ run 'bundle --local'
+ run 'rails g steak:install'
end
def append_to(path, content)
rails_project_path.join(path).open('a') { |f| f.write content }
end
def run(command)
- output = Bundler.with_clean_env { `#{command} 2>&1` }
+ self.output = Bundler.with_clean_env { `#{command} 2>&1` }
log "$ #{command}"
- log output
+ log self.output
raise "`#{command}` failed with:\n#{output}" unless $?.success?
end
def path(path)
rails_project_path.join(path)
end
+ def content_of(path)
+ File.read path(path)
+ end
+
+ def cd(*args)
+ silence_warnings { Dir.chdir(*args) }
+ end
+
+ def rm_rf(*args)
+ FileUtils.rm_rf *args
+ end
+
def root_path
- Pathname.new(__FILE__).join('../../..')
+ Bundler.root
end
def rails_project_path
View
@@ -23,4 +23,5 @@ Gem::Specification.new do |s|
# s.add_dependency 'capybara', '>= 1.0.0'
s.add_development_dependency 'rails', '>= 3.0.0'
+ s.add_development_dependency 'sqlite3'
end

0 comments on commit 8ab298c

Please sign in to comment.