steak 0.4.0.a3 → 0.4.0.a4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -36,11 +36,13 @@ If you are not in Rails but use RSpec, then Steak is just some aliases providing
36
36
 
37
37
  == Getting started
38
38
 
39
+ <em><b>NOTE:</b> Please note that the stable version of Steak only works with Rails 2.x and RSpec 1.x. If you want to try with Rails 3 or RSpec 2, then you can install the prerelease version of Steak (using <tt>gem install steak --pre</tt>) which is based on the experimental <tt>rails3</tt> branch.</em>
40
+
39
41
  === Not in Rails
40
42
 
41
43
  Just install and require the damned gem!
42
44
 
43
- $ [sudo] gem install steak
45
+ $ gem install steak
44
46
 
45
47
  Then in your spec or spec helper:
46
48
 
@@ -50,23 +52,27 @@ That's all. You don't really need to require RSpec.
50
52
 
51
53
  === In Rails
52
54
 
53
- Assuming you have already setup rspec-rails, add this to your project's <tt>config/environments/test.rb</tt>:
55
+ Assuming you have already setup rspec-rails, add this to your project's <tt>Gemfile</tt>:
54
56
 
55
- config.gem "steak"
57
+ gem 'steak', '0.4.0.a3'
56
58
 
57
- Install the gem from the command line:
59
+ And install it:
58
60
 
59
- $ [sudo] RAILS_ENV=test rake gems:install
61
+ $ bundle install
60
62
 
61
63
  Run the generator:
62
64
 
63
- $ script/generate steak
65
+ $ rails generate steak
66
+
67
+ That will create some basic helper files and directory structure under the +spec/acceptance+ directory, already configured for +Capybara+. If you want to use +Webrat+, just pass it to the generator:
68
+
69
+ $ rails generate steak --webrat
64
70
 
65
- That will create some basic helper files and directory structure under the +spec/acceptance+ directory, already configured for +Webrat+. Spend one minute on getting familiar with the structure and files you've got.
71
+ Spend one minute on getting familiar with the structure and files you've got.
66
72
 
67
73
  Now you may want to create your first acceptance spec:
68
74
 
69
- $ script/generate acceptance_spec this_is_my_first_feature
75
+ $ rails generate acceptance_spec this_is_my_first_feature
70
76
 
71
77
  You run your acceptance specs just like your regular specs. Individually...
72
78
 
@@ -82,6 +88,11 @@ You run your acceptance specs just like your regular specs. Individually...
82
88
 
83
89
  == Credits
84
90
 
85
- Steak is developed and maintained by Luismi Cavallé with the help and support of the rest of the BeBanjo team: Sergio Gil and Jorge Gómez Sancha.
91
+ Steak was created by Luismi Cavallé and improved thanks to the love from:
92
+
93
+ - Álvaro Bautista
94
+ - Felipe Talavera
95
+ - Paco Guzmán
96
+ - Jeff Kreeftmeijer
86
97
 
87
- Copyright (c) 2009 Luismi Cavallé, released under the MIT license
98
+ Copyright (c) 2009, 2010 Luismi Cavallé, released under the MIT license
@@ -1,16 +1,28 @@
1
1
  require 'rails/generators'
2
2
 
3
3
  class SteakGenerator < Rails::Generators::Base
4
+ class_option :webrat, :desc => 'Use Webrat.', :type => :boolean
5
+ class_option :capybara, :desc => 'Use Capybara.', :type => :boolean
6
+
7
+ def initialize(args=[], options={}, config={})
8
+ puts "Defaulting to Capybara..." if options.empty?
9
+ super
10
+ end
11
+
4
12
  def manifest
5
13
  empty_directory 'spec/controllers'
6
14
  empty_directory 'spec/acceptance/support'
7
15
  empty_directory 'lib/tasks'
8
- copy_file "acceptance_helper.rb", "spec/acceptance/acceptance_helper.rb"
16
+ template "acceptance_helper.rb", "spec/acceptance/acceptance_helper.rb"
9
17
  copy_file "helpers.rb", "spec/acceptance/support/helpers.rb"
10
18
  copy_file "paths.rb", "spec/acceptance/support/paths.rb"
11
19
  copy_file "steak.rake", "lib/tasks/steak.rake"
12
20
  end
13
-
21
+
22
+ def driver
23
+ @driver = options.webrat? ? 'webrat' : 'capybara'
24
+ end
25
+
14
26
  def self.source_root
15
27
  File.join(File.dirname(__FILE__), 'templates')
16
28
  end
@@ -1,10 +1,31 @@
1
1
  require File.dirname(__FILE__) + "/../spec_helper"
2
2
  require "steak"
3
+ <%- if driver == 'webrat' %>
3
4
  require "webrat"
4
5
 
5
6
  Webrat.configure do |config|
6
- config.mode = :rails
7
+ config.mode = :rack
7
8
  end
8
9
 
10
+ module AppHelper
11
+ def app
12
+ Rails.application
13
+ end
14
+ end
15
+
16
+ Rspec.configure do |config|
17
+ config.include Rack::Test::Methods
18
+ config.include Webrat::Methods
19
+ config.include Webrat::Matchers
20
+ config.include AppHelper
21
+ end
22
+ <%- else -%>
23
+ require 'capybara/rails'
24
+
25
+ Rspec.configure do |config|
26
+ config.include Capybara
27
+ end
28
+ <%- end -%>
29
+
9
30
  # Put your acceptance spec helpers inside /spec/acceptance/support
10
31
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
@@ -12,26 +12,38 @@ module Factories
12
12
  end
13
13
  path
14
14
  end
15
-
15
+
16
16
  def create_rails_app(options = {})
17
17
  path = File.join(Dir.tmpdir, String.random, "rails_app")
18
18
  FileUtils.rm_rf path
19
19
  `rails #{path}`
20
+ FileUtils.rm_rf path + '/public/index.html'
21
+ File.open(File.join(path, "Gemfile"), "a") do |file|
22
+ file.write "\ngem 'rspec-rails', '>= 2.0.0.a9'\n" <<
23
+ "gem 'capybara'\n"
24
+ end
25
+
20
26
  File.open(File.join(path, "Gemfile"), "a") do |file|
21
- file.write "\ngem 'rspec-rails', '>= 2.0.0.a9'\n"
27
+ file.write "\ngem 'steak', :path => '#{File.expand_path(File.dirname(__FILE__) + '/../..')}'\n"
28
+ end
29
+
30
+ Dir.chdir path do
31
+ `rails generate rspec:install`
32
+ if options[:scaffold]
33
+ `rails generate scaffold #{options[:scaffold]}`
34
+ `rake db:create db:migrate db:test:prepare`
35
+ end
22
36
  end
23
- FileUtils.cp_r File.dirname(__FILE__) + "/../../", path + "/vendor/plugins/steak"
24
-
37
+
25
38
  unless options[:setup_steak] == false
26
39
  Dir.chdir path do
27
- `rails generate rspec:install`
28
40
  `rails generate steak`
29
41
  end
30
42
  end
31
-
43
+
32
44
  path
33
45
  end
34
-
46
+
35
47
  end
36
48
 
37
49
  module HelperMethods
@@ -40,9 +52,9 @@ module HelperMethods
40
52
  current_dir = Dir.pwd
41
53
  Dir.chdir app_base
42
54
  end
43
-
55
+
44
56
  output = `rspec #{file_path} 2>&1`
45
-
57
+
46
58
  Dir.chdir current_dir if app_base
47
59
  output
48
60
  end
@@ -52,7 +64,7 @@ class String
52
64
  unless const_defined?("CHARS")
53
65
  CHARS = ('a'..'z').to_a + ('A'..'Z').to_a
54
66
  end
55
-
67
+
56
68
  def self.random(size = 8)
57
69
  (0..size).map{ CHARS[rand(CHARS.length)] }.join
58
70
  end
@@ -30,12 +30,12 @@ feature "Acceptance spec execution", %q{
30
30
  feature "Minimal spec" do
31
31
  scenario "First scenario" do
32
32
  get "/"
33
- response.should contain(/Welcome aboard/)
33
+ response.should contain(/No route matches/)
34
34
  end
35
35
  end
36
36
  SPEC
37
37
  output = run_spec spec_file, File.join(File.dirname(spec_file), '../..')
38
- output.should =~ /1 example, 0 failures/
38
+ output.should =~ /1 example, 1 failures/
39
39
  end
40
40
 
41
41
  end
@@ -5,20 +5,63 @@ feature "Steak generator for rails", %q{
5
5
  As a developer
6
6
  I want to run a generator that sets everything up for me
7
7
  } do
8
-
8
+
9
9
  scenario "Running generator in an empty project" do
10
-
10
+
11
11
  rails_app = create_rails_app(:setup_steak => false)
12
-
12
+
13
13
  Dir.chdir rails_app do
14
14
  `rails generate steak`
15
15
  end
16
-
16
+
17
17
  File.exist?(rails_app + "/spec/acceptance/acceptance_helper.rb").should be_true
18
18
  File.exist?(rails_app + "/spec/acceptance/support/helpers.rb").should be_true
19
19
  File.exist?(rails_app + "/spec/acceptance/support/paths.rb").should be_true
20
20
  File.exist?(rails_app + "/lib/tasks/steak.rake").should be_true
21
-
21
+
22
+ end
23
+
24
+ scenario "Running generator with capybara by default" do
25
+ rails_app = create_rails_app(:setup_steak => false, :scaffold => :users)
26
+
27
+ Dir.chdir rails_app do
28
+ `rails generate steak`
29
+ end
30
+
31
+ spec_file = create_spec :path => rails_app + "/spec/acceptance",
32
+ :content => <<-SPEC
33
+ require File.dirname(__FILE__) + "/acceptance_helper.rb"
34
+ feature "Capybara spec" do
35
+ scenario "First scenario" do
36
+ visit "/users"
37
+ page.should have_content('Listing users')
38
+ end
39
+ end
40
+ SPEC
41
+ output = run_spec spec_file, rails_app
42
+ output.should =~ /1 example, 0 failures/
43
+ end
44
+
45
+ scenario "Running generator with webrat" do
46
+ rails_app = create_rails_app(:setup_steak => false, :scaffold => :users)
47
+
48
+ Dir.chdir rails_app do
49
+ `rails generate steak --webrat`
50
+ end
51
+
52
+ spec_file = create_spec :path => rails_app + "/spec/acceptance",
53
+ :content => <<-SPEC
54
+ require File.dirname(__FILE__) + "/acceptance_helper.rb"
55
+ feature "Webrat spec" do
56
+ scenario "First scenario" do
57
+ visit "/users"
58
+ response_body.should contain('Listing users')
59
+ end
60
+ end
61
+ SPEC
62
+
63
+ output = run_spec spec_file, rails_app
64
+ output.should =~ /1 example, 0 failures/
22
65
  end
23
-
24
- end
66
+
67
+ end
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 4
8
8
  - 0
9
- - a3
10
- version: 0.4.0.a3
9
+ - a4
10
+ version: 0.4.0.a4
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Luismi Cavall\xC3\xA9"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-04-05 00:00:00 +02:00
18
+ date: 2010-05-04 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency