steak 0.4.0.beta.1 → 1.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/README.rdoc +94 -48
  2. data/Rakefile +1 -1
  3. data/lib/rspec-1/rails/generators/acceptance_spec/USAGE +1 -0
  4. data/lib/rspec-1/rails/generators/acceptance_spec/acceptance_spec_generator.rb +9 -0
  5. data/lib/{generators → rspec-1/rails/generators}/acceptance_spec/templates/acceptance_spec.rb +2 -3
  6. data/lib/{generators → rspec-1/rails/generators}/steak/USAGE +4 -4
  7. data/lib/rspec-1/rails/generators/steak/steak_generator.rb +26 -0
  8. data/lib/rspec-1/rails/generators/steak/templates/acceptance_helper.rb +18 -0
  9. data/lib/rspec-1/rails/generators/steak/templates/helpers.rb +5 -0
  10. data/lib/rspec-1/rails/generators/steak/templates/paths.rb +9 -0
  11. data/lib/rspec-1/rails/generators/steak/templates/steak.rake +19 -0
  12. data/lib/rspec-1/steak.rb +23 -0
  13. data/lib/rspec-2/rails/generators/install_generator.rb +39 -0
  14. data/lib/rspec-2/rails/generators/spec_generator.rb +33 -0
  15. data/lib/{generators/steak → rspec-2/rails/generators}/templates/acceptance_helper.rb +8 -10
  16. data/lib/rspec-2/rails/generators/templates/acceptance_spec.rb +12 -0
  17. data/lib/rspec-2/rails/generators/templates/helpers.rb +5 -0
  18. data/lib/rspec-2/rails/generators/templates/paths.rb +9 -0
  19. data/lib/rspec-2/rails/railtie.rb +14 -0
  20. data/lib/{generators/steak/templates → rspec-2/rails/tasks}/steak.rake +2 -2
  21. data/lib/rspec-2/steak.rb +22 -0
  22. data/lib/steak.rb +8 -10
  23. data/spec/acceptance/rspec-1/acceptance_helper.rb +95 -0
  24. data/spec/acceptance/{acceptance_spec_generator_spec.rb → rspec-1/acceptance_spec_generator_spec.rb} +14 -15
  25. data/spec/acceptance/{basic_spec.rb → rspec-1/basic_spec.rb} +7 -8
  26. data/spec/acceptance/{rails_spec.rb → rspec-1/rails_spec.rb} +10 -12
  27. data/spec/acceptance/{steak_generator_spec.rb → rspec-1/steak_generator_spec.rb} +22 -26
  28. data/spec/acceptance/rspec-2/acceptance_helper.rb +87 -0
  29. data/spec/acceptance/rspec-2/basic_spec.rb +78 -0
  30. data/spec/acceptance/rspec-2/rails_spec.rb +89 -0
  31. data/spec/acceptance/rspec-2/steak_install_generator_spec.rb +66 -0
  32. data/spec/acceptance/rspec-2/steak_spec_generator_spec.rb +63 -0
  33. metadata +112 -26
  34. data/init.rb +0 -8
  35. data/lib/generators/acceptance_spec/USAGE +0 -0
  36. data/lib/generators/acceptance_spec/acceptance_spec_generator.rb +0 -13
  37. data/lib/generators/steak/steak_generator.rb +0 -29
  38. data/lib/generators/steak/templates/helpers.rb +0 -6
  39. data/lib/generators/steak/templates/paths.rb +0 -9
  40. data/spec/acceptance/acceptance_helper.rb +0 -76
@@ -6,33 +6,39 @@ http://dl.dropbox.com/u/645329/steak_small.jpg
6
6
 
7
7
  == What is Steak?
8
8
 
9
- Steak is like Cucumber but in plain Ruby. This is how an acceptance spec looks like in Steak:
9
+ Steak is like Cucumber but in plain Ruby. This is how an acceptance spec looks
10
+ like in Steak:
10
11
 
11
12
  feature "Main page" do
12
-
13
+
13
14
  background do
14
15
  create_user :login => "jdoe"
15
16
  login_as "jdoe"
16
17
  end
17
-
18
+
18
19
  scenario "should show existing quotes" do
19
- create_quote :text => "The language of friendship is not words, but meanings",
20
+ create_quote :text => "The language of friendship is not words, but meanings",
20
21
  :author => "Henry David Thoreau"
21
22
 
22
23
  visit "/"
23
-
24
+
24
25
  page.should have_css(".quote", :count => 1)
25
26
  within(:css, ".quote") do
26
27
  page.should have_css(".text", :text => "The language of friendship is not words, but meanings")
27
28
  page.should have_css(".author", :text => "Henry David Thoreau")
28
29
  end
29
30
  end
30
-
31
+
31
32
  end
32
-
33
- No explicit givens, whens or thens. No steps, no english, just Ruby: RSpec, Steak and, in this example, some factories and Capybara. That's all.
34
33
 
35
- If you are not in Rails but use RSpec, then Steak is just some aliases providing you with the language of acceptance testing (+feature+, +scenario+, +background+). If you are in Rails, you also have a couple of generators, a rake task and full Rails integration testing (meaning Webrat support, for instance)
34
+ No explicit givens, whens or thens. No steps, no english, just Ruby: RSpec,
35
+ Steak and, in this example, some factories and Capybara. That's all.
36
+
37
+ If you are not in Rails but use RSpec, then Steak is just some aliases
38
+ providing you with the language of acceptance testing (+feature+, +scenario+,
39
+ +background+). If you are in Rails, you also have a couple of generators, a
40
+ rake task and full Rails integration testing (meaning Webrat support, for
41
+ instance)
36
42
 
37
43
  == Getting started
38
44
 
@@ -42,27 +48,32 @@ Just install and require the damned gem!
42
48
 
43
49
  $ gem install steak
44
50
 
51
+ (Add the <tt>--pre</tt> modifier to be on top of RSpec 2 instead of RSpec 1.x)
52
+
45
53
  Then in your spec or spec helper:
46
54
 
47
55
  require 'steak'
48
-
56
+
49
57
  That's all. You don't really need to require RSpec.
50
58
 
51
59
  === In Rails 2.x (stable branch)
52
60
 
53
- Assuming you have already setup rspec-rails, add this to your project's <tt>config/environments/test.rb</tt>:
61
+ Assuming you have already setup rspec-rails, add this to your project's
62
+ <tt>config/environments/test.rb</tt>:
63
+
64
+ config.gem "steak", :lib => false
54
65
 
55
- config.gem "steak"
56
-
57
66
  Install the gem from the command line:
58
-
67
+
59
68
  $ RAILS_ENV=test rake gems:install
60
-
69
+
61
70
  Run the generator:
62
71
 
63
72
  $ script/generate steak
64
-
65
- 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:
73
+
74
+ That will create some basic helper files and directory structure under the
75
+ <tt>spec/acceptance</tt> directory, already configured for +Capybara+. If you want to
76
+ use +Webrat+, just pass it to the generator:
66
77
 
67
78
  $ script/generate steak --webrat
68
79
 
@@ -71,64 +82,92 @@ Spend one minute on getting familiar with the structure and files you've got.
71
82
  Now you may want to create your first acceptance spec:
72
83
 
73
84
  $ script/generate acceptance_spec this_is_my_first_feature
74
-
85
+
75
86
  You run your acceptance specs just like your regular specs. Individually...
76
87
 
77
- $ spec spec/acceptance/this_is_my_first_feature_spec.rb
78
-
88
+ $ rspec spec/acceptance/this_is_my_first_feature_spec.rb
89
+
79
90
  ...or all together:
80
91
 
81
- $ spec spec/acceptance
82
-
92
+ $ rspec spec/acceptance
93
+
83
94
  ...you can also do:
84
95
 
85
96
  $ rake spec:acceptance
86
-
97
+
87
98
  === In Rails 3 (master branch)
88
99
 
89
100
  Add this to your project's <tt>Gemfile</tt>:
90
101
 
91
- gem 'steak', '>= 0.4.0.a5'
92
-
93
- And install it:
94
-
102
+ group :development, :test do
103
+ gem 'rspec-rails', '>= 2.0.0.beta.19'
104
+ gem 'steak', :git => 'git://github.com/cavalle/steak.git'
105
+ gem 'capybara'
106
+
107
+ # Other usual suspects:
108
+ # gem 'delorean'
109
+ # gem 'database_cleaner'
110
+ # gem 'spork'
111
+ end
112
+
113
+ And install:
114
+
95
115
  $ bundle install
96
-
97
- Run the generator:
98
116
 
99
- $ rails generate steak
100
-
101
- 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:
117
+ Run the generators:
118
+
119
+ $ rails g rspec:install
120
+ $ rails g steak:install
102
121
 
103
- $ rails generate steak --webrat
122
+ That will create some basic helper files and directory structure under the
123
+ <tt>spec/acceptance</tt> directory, already configured for +Capybara+.
104
124
 
105
125
  Spend one minute on getting familiar with the structure and files you've got.
106
126
 
107
127
  Now you may want to create your first acceptance spec:
108
128
 
109
- $ rails generate acceptance_spec this_is_my_first_feature
110
-
129
+ $ rails generate steak:spec this_is_my_first_feature
130
+
111
131
  You run your acceptance specs just like your regular specs. Individually...
112
132
 
113
- $ spec spec/acceptance/this_is_my_first_feature_spec.rb
114
-
133
+ $ rspec spec/acceptance/this_is_my_first_feature_spec.rb
134
+
115
135
  ...or all together:
116
136
 
117
- $ spec spec/acceptance
118
-
137
+ $ rspec spec/acceptance
138
+
119
139
  ...you can also do:
120
140
 
121
141
  $ rake spec:acceptance
122
142
 
143
+ == RSpec & Metadata
144
+
145
+ Steak scenarios are just regular RSpec examples with their metadata attribute
146
+ <tt>:type</tt> set to <tt>:acceptance</tt>. That's useful if you want to make sure you
147
+ include helpers or set hooks only for your acceptance specs and not for the
148
+ rest of the specs in your suite.
149
+
150
+ You'd do it this way:
151
+
152
+ RSpec.configure do |config|
153
+ # include MyHelpers module in every acceptance spec
154
+ config.include MyHelpers, :type => :acceptance
155
+
156
+ config.before(:each, :type => :acceptance) do
157
+ # Some code to run before any acceptance spec
158
+ end
159
+ end
160
+
123
161
  == Resources
124
162
 
125
- * Source: http://github.com/cavalle/steak
126
- * Issues: http://github.com/cavalle/steak/issues
127
- * Hashtag: #steakrb
128
- * Group: http://groups.google.com/group/steakrb
129
- * IRC channel: #steakrb on freenode
130
- * Tutorial: http://jeffkreeftmeijer.com/2010/steak-because-cucumber-is-for-vegetarians/
131
-
163
+ - Source: http://github.com/cavalle/steak
164
+ - Issues: http://github.com/cavalle/steak/issues
165
+ - Group: http://groups.google.com/group/steakrb
166
+ - IRC channel: #steakrb on freenode
167
+ - Tutorial: http://jeffkreeftmeijer.com/2010/steak-because-cucumber-is-for-vegetarians/
168
+ - Hashtag: #steakrb
169
+ - More resources: http://wiki.github.com/cavalle/steak/resources
170
+
132
171
  == Credits
133
172
 
134
173
  Steak was created by Luismi Cavallé and improved thanks to the love from:
@@ -140,5 +179,12 @@ Steak was created by Luismi Cavallé and improved thanks to the love from:
140
179
  - Jaime Iniesta
141
180
  - Emili Parreño
142
181
  - Andreas Wolff
143
-
144
- Copyright (c) 2009, 2010 Luismi Cavallé, released under the MIT license
182
+ - Wincent Colaiuta
183
+ - Falk Pauser
184
+ - Francesc Esplugas
185
+ - Raúl Murciano
186
+ - Enable Interactive
187
+ - Vojto Rinik
188
+ - Fred Wu
189
+
190
+ Copyright (c) 2009, 2010 Luismi Cavallé, released under the MIT license
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ desc 'Default: run specs.'
7
7
  task :default => :spec
8
8
 
9
9
  desc 'Run specs for the steak plugin.'
10
- Rspec::Core::RakeTask.new(:spec) do |t|
10
+ RSpec::Core::RakeTask.new(:spec) do |t|
11
11
  t.pattern = FileList["spec/**/*_spec.rb"]
12
12
  end
13
13
 
@@ -0,0 +1,9 @@
1
+ class AcceptanceSpecGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ m.directory File.join('spec/acceptance', class_path)
5
+ file_name.gsub!(/_spec$/,"")
6
+ m.template 'acceptance_spec.rb', File.join('spec/acceptance', class_path, "#{file_name}_spec.rb")
7
+ end
8
+ end
9
+ end
@@ -5,9 +5,8 @@ feature "Feature name", %q{
5
5
  As a ...
6
6
  I want to ...
7
7
  } do
8
-
8
+
9
9
  scenario "Scenario name" do
10
10
  true.should == true
11
11
  end
12
-
13
- end
12
+ end
@@ -1,8 +1,8 @@
1
1
  Description:
2
2
  Sets up Steak in your Rails project. This will generate the spec/acceptance directory
3
3
  and the necessary files.
4
-
5
- If you haven't already, You should also run `rails generate rspec:install` to complete the set up.
6
-
4
+
5
+ If you haven't already, You should also run `./script/generate rspec` to complete the set up.
6
+
7
7
  Examples:
8
- `rails generate steak`
8
+ `./script/generate steak`
@@ -0,0 +1,26 @@
1
+ class SteakGenerator < Rails::Generator::Base
2
+ default_options :driver => 'capybara'
3
+
4
+ def initialize(runtime_args, runtime_options = {})
5
+ puts "Defaulting to Capybara..." if runtime_args.empty?
6
+ super
7
+ end
8
+
9
+ def manifest
10
+ record do |m|
11
+ m.directory 'spec/acceptance/support'
12
+ m.directory 'lib/tasks'
13
+ m.template "acceptance_helper.rb", "spec/acceptance/acceptance_helper.rb"
14
+ m.file "helpers.rb", "spec/acceptance/support/helpers.rb"
15
+ m.file "paths.rb", "spec/acceptance/support/paths.rb"
16
+ m.file "steak.rake", "lib/tasks/steak.rake"
17
+ end
18
+ end
19
+
20
+ def add_options!(opt)
21
+ opt.separator ''
22
+ opt.separator 'Options:'
23
+ opt.on('--capybara', 'Use Capybara (default).') { |v| options[:driver] = 'capybara' }
24
+ opt.on('--webrat', 'Use Webrat.') { |v| options[:driver] = 'webrat' }
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+ require "steak"
3
+ <%- if options[:driver] == 'webrat' %>
4
+ require "webrat"
5
+
6
+ Webrat.configure do |config|
7
+ config.mode = :rails
8
+ end
9
+ <%- else -%>
10
+ require 'capybara/rails'
11
+
12
+ Spec::Runner.configure do |config|
13
+ config.include Capybara
14
+ end
15
+ <%- end -%>
16
+
17
+ # Put your acceptance spec helpers inside /spec/acceptance/support
18
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
@@ -0,0 +1,5 @@
1
+ module HelperMethods
2
+ # Put helper methods you need to be available in all tests here.
3
+ end
4
+
5
+ Spec::Runner.configuration.include(HelperMethods)
@@ -0,0 +1,9 @@
1
+ module NavigationHelpers
2
+ # Put helper methods related to the paths in your application here.
3
+
4
+ def homepage
5
+ "/"
6
+ end
7
+ end
8
+
9
+ Spec::Runner.configuration.include(NavigationHelpers)
@@ -0,0 +1,19 @@
1
+ unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
2
+
3
+ require 'spec/rake/spectask'
4
+
5
+ namespace :spec do
6
+ desc "Run the code examples in spec/acceptance"
7
+ Spec::Rake::SpecTask.new(:acceptance => "db:test:prepare") do |t|
8
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
9
+ t.spec_files = FileList["spec/acceptance/**/*_spec.rb"]
10
+ end
11
+
12
+ # Setup stats to include acceptance specs
13
+ task :statsetup do
14
+ require 'code_statistics'
15
+ ::STATS_DIRECTORIES << %w(Acceptance\ specs spec/acceptance) if File.exist?('spec/acceptance')
16
+ ::CodeStatistics::TEST_TYPES << "Acceptance specs" if File.exist?('spec/acceptance')
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ module Spec::Example::ExampleGroupMethods
2
+ alias scenario example
3
+ alias background before
4
+ end
5
+
6
+ module Spec::DSL::Main
7
+ alias feature describe
8
+ end
9
+
10
+ if defined?(Spec::Rails)
11
+ module Spec::Rails::Example
12
+ class AcceptanceExampleGroup < IntegrationExampleGroup
13
+ include ActionController::RecordIdentifier
14
+ Spec::Example::ExampleGroupFactory.register(:acceptance, self)
15
+
16
+ def method_missing(sym, *args, &block)
17
+ return Spec::Matchers::Be.new(sym, *args) if sym.to_s =~ /^be_/
18
+ return Spec::Matchers::Has.new(sym, *args) if sym.to_s =~ /^have_/
19
+ super
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,39 @@
1
+ require 'rails/generators'
2
+
3
+ module Steak
4
+ class InstallGenerator < Rails::Generators::Base
5
+ class_option :webrat, :desc => 'Use Webrat.', :type => :boolean
6
+ class_option :capybara, :desc => 'Use Capybara.', :type => :boolean
7
+
8
+ source_root File.join(File.dirname(__FILE__), 'templates')
9
+
10
+ desc <<-DESC
11
+ Description:
12
+ Sets up Steak in your Rails project. This will generate the
13
+ spec/acceptance directory and the necessary files.
14
+
15
+ If you haven't already, You should also run
16
+ `rails generate rspec:install` to complete the set up.
17
+
18
+ Examples:
19
+ `rails generate steak:install`
20
+ DESC
21
+
22
+ def initialize(args=[], options={}, config={})
23
+ puts "Defaulting to Capybara..." if options.empty?
24
+ super
25
+ end
26
+
27
+ def manifest
28
+ empty_directory 'spec/controllers'
29
+ empty_directory 'spec/acceptance/support'
30
+ template "acceptance_helper.rb", "spec/acceptance/acceptance_helper.rb"
31
+ copy_file "helpers.rb", "spec/acceptance/support/helpers.rb"
32
+ copy_file "paths.rb", "spec/acceptance/support/paths.rb"
33
+ end
34
+
35
+ def driver
36
+ @driver = options.webrat? ? 'webrat' : 'capybara'
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,33 @@
1
+ require 'rails/generators'
2
+ require 'active_support/inflector/inflections'
3
+
4
+ module Steak
5
+ class SpecGenerator < Rails::Generators::NamedBase
6
+ source_root File.join(File.dirname(__FILE__), 'templates')
7
+
8
+ desc <<-DESC
9
+ Description:
10
+ Create an acceptance spec for the feature NAME in the
11
+ 'spec/acceptance' folder.
12
+
13
+ Example:
14
+ `rails generate steak:spec checkout`
15
+
16
+ Creates an acceptance spec for the "checkout" feature:
17
+ spec/acceptance/checkout_spec.rb
18
+ DESC
19
+
20
+ def manifest
21
+ empty_directory File.join('spec/acceptance', class_path)
22
+ file_name.gsub!(/_spec$/, "")
23
+
24
+ @feature_name = file_name.titleize
25
+ @relative_path = "../" * class_path.size
26
+
27
+ target = File.join('spec/acceptance', class_path,
28
+ "#{file_name}_spec.rb")
29
+
30
+ template 'acceptance_spec.rb', target
31
+ end
32
+ end
33
+ end