Skip to content

Commit

Permalink
Rake support
Browse files Browse the repository at this point in the history
  • Loading branch information
cavalle committed Mar 14, 2011
1 parent d22f76c commit 77d9971
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ _NOTE: The latest version of Steak assumes that you're testing a Rails 3 applica

It's super-easy to get you started. Just add the gem to your `Gemfile`

group 'test' do
group :test, :development do
gem 'steak'
# ...

Expand Down
11 changes: 10 additions & 1 deletion lib/steak.rb
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
require 'capybara/rspec'
require 'capybara/rspec'
require 'rspec-rails'

module Steak
class Railtie < ::Rails::Railtie
rake_tasks do
load "tasks/steak_tasks.rake"
end
end
end
6 changes: 6 additions & 0 deletions lib/tasks/steak_tasks.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace :spec do
desc "Run the acceptance specs in spec/acceptance"
RSpec::Core::RakeTask.new(:acceptance => "db:test:prepare") do |t|
t.pattern = "spec/acceptance/**/*_spec.rb"
end
end
2 changes: 1 addition & 1 deletion spec/acceptance/getting_started_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
generate_rails_project

append_to 'Gemfile', <<-GEMS
group :test do
group :test, :development do
gem 'steak', :path => '#{root_path}'
end
GEMS
Expand Down
35 changes: 35 additions & 0 deletions spec/acceptance/rake_support_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'spec_helper'

feature 'Rake support', %q{
In order to conveniently run my specs along with the rest of my test suite
As a Rails developer
I want rake support in Steak
} do

background do
generate_rails_project_with_steak
create_file 'spec/unit_spec.rb', <<-RSPEC
require 'spec_helper'
describe Object do
it { should respond_to :to_s }
end
RSPEC
run 'rails g steak:spec my_spec'
run 'rake db:migrate'
end

scenario 'to run acceptance specs as part of the test suite' do
run 'rake spec'
output.should =~ /2 examples, 0 failures/

run 'rake'
output.should =~ /2 examples, 0 failures/
end

scenario 'to run only acceptance specs' do
run 'rake spec:acceptance'
output.should =~ /1 example, 0 failures/
end

end
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rubygems'
require 'bundler/setup'

require 'capybara/rspec'
require 'active_support/all'
require 'rails'
require 'steak'

require 'support/helpers'
6 changes: 5 additions & 1 deletion spec/support/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def generate_rails_project_with_steak
generate_rails_project

append_to 'Gemfile', <<-RUBY
group(:test) do
group :test, :development 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
Expand All @@ -28,6 +28,10 @@ def append_to(path, content)
rails_project_path.join(path).open('a') { |f| f.write content }
end

def create_file(path, content)
rails_project_path.join(path).open('w') { |f| f.write content }
end

def run(command)
self.output = Bundler.with_clean_env { `#{command} 2>&1` }

Expand Down

0 comments on commit 77d9971

Please sign in to comment.