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
@@ -7,24 +7,22 @@ Webrat.configure do |config|
7
7
  config.mode = :rack
8
8
  end
9
9
 
10
- module AppHelper
10
+ module Steak::Webrat
11
+ include Rack::Test::Methods
12
+ include Webrat::Methods
13
+ include Webrat::Matchers
14
+
11
15
  def app
12
16
  Rails.application
13
17
  end
14
18
  end
15
19
 
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
20
+ RSpec.configuration.include Steak::Webrat, :type => :acceptance
21
+
22
22
  <%- else -%>
23
23
  require 'capybara/rails'
24
24
 
25
- Rspec.configure do |config|
26
- config.include Capybara
27
- end
25
+ RSpec.configuration.include Capybara, :type => :acceptance
28
26
  <%- end -%>
29
27
 
30
28
  # Put your acceptance spec helpers inside /spec/acceptance/support
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/<%= @relative_path %>acceptance_helper'
2
+
3
+ feature "<%= @feature_name %>", %q{
4
+ In order to ...
5
+ As a ...
6
+ I want to ...
7
+ } do
8
+
9
+ scenario "Scenario name" do
10
+ true.should == true
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module HelperMethods
2
+ # Put helper methods you need to be available in all tests here.
3
+ end
4
+
5
+ RSpec.configuration.include HelperMethods, :type => :acceptance
@@ -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
+ RSpec.configuration.include NavigationHelpers, :type => :acceptance
@@ -0,0 +1,14 @@
1
+ require 'steak'
2
+ require 'rails'
3
+
4
+ module Steak
5
+ class Railtie < ::Rails::Railtie
6
+ rake_tasks do
7
+ load File.dirname(__FILE__) + "/tasks/steak.rake"
8
+ end
9
+ generators do
10
+ require File.dirname(__FILE__) + "/generators/install_generator"
11
+ require File.dirname(__FILE__) + "/generators/spec_generator"
12
+ end
13
+ end
14
+ end
@@ -2,10 +2,10 @@ require 'rspec/core/rake_task'
2
2
 
3
3
  namespace :spec do
4
4
  desc "Run the code examples in spec/acceptance"
5
- Rspec::Core::RakeTask.new(:acceptance => "db:test:prepare") do |t|
5
+ RSpec::Core::RakeTask.new(:acceptance => "db:test:prepare") do |t|
6
6
  t.pattern = "spec/acceptance/**/*_spec.rb"
7
7
  end
8
-
8
+
9
9
  task :statsetup do
10
10
  require 'rails/code_statistics'
11
11
  ::STATS_DIRECTORIES << %w(Acceptance\ specs spec/acceptance) if File.exist?('spec/acceptance')
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + '/rails/railtie' if defined?(Rails)
2
+
3
+ module Steak
4
+ module AcceptanceExampleGroup
5
+ def self.included(base)
6
+ base.instance_eval do
7
+ alias scenario example
8
+ alias background before
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ module RSpec::Core::ObjectExtensions
15
+ def feature(*args, &block)
16
+ args << {} unless args.last.is_a?(Hash)
17
+ args.last.update :type => :acceptance, :steak => true
18
+ describe(*args, &block)
19
+ end
20
+ end
21
+
22
+ RSpec.configuration.include Steak::AcceptanceExampleGroup, :type => :acceptance
@@ -1,13 +1,11 @@
1
- require 'rubygems'
2
- require 'rspec'
3
-
4
- class Rspec::Core::ExampleGroup
5
- class << self
6
- alias scenario example
7
- alias background before
8
- end
1
+ begin
2
+ require 'rspec/core'
3
+ rescue LoadError
4
+ require 'spec'
9
5
  end
10
6
 
11
- module Rspec::Core::ObjectExtensions
12
- alias feature describe
7
+ if defined?(RSpec)
8
+ require 'rspec-2/steak'
9
+ else
10
+ require 'rspec-1/steak'
13
11
  end
@@ -0,0 +1,95 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ require File.dirname(__FILE__) + "/../../../lib/steak"
4
+ require 'tempfile'
5
+
6
+ module RSpec_1
7
+ module Factories
8
+
9
+ def create_spec(options)
10
+ options = {:content => options} unless options.is_a?(Hash)
11
+ path = (options[:path] || current_dir) + "/#{String.random}_spec.rb"
12
+ File.open(path, "w") do |file|
13
+ file.write options[:content]
14
+ end
15
+ path
16
+ end
17
+
18
+ def create_rails_app(options = {})
19
+ path = current_dir + "/rails_app_#{String.random}"
20
+ FileUtils.rm_rf path
21
+ run "rails #{path}"
22
+ FileUtils.rm path + '/public/index.html'
23
+ File.open(path + "/config/environments/test.rb", "a") do |file|
24
+ file.write <<-CONFIG
25
+ config.gem 'rspec-rails', :lib => false
26
+ CONFIG
27
+ end
28
+ FileUtils.cp_r steak_dir, path + "/vendor/plugins/steak"
29
+
30
+ Dir.chdir path do
31
+ run "script/generate rspec"
32
+ end
33
+
34
+ unless options[:setup_steak] == false
35
+ Dir.chdir path do
36
+ run "script/generate steak"
37
+ end
38
+ end
39
+
40
+ path
41
+ end
42
+
43
+ end
44
+
45
+ module HelperMethods
46
+ def run(cmd)
47
+ `rvm 1.8.7-p249@steak-rspec-1 exec #{cmd} 2>&1`.tap do |o|
48
+ puts o if ENV['TRACE']
49
+ end
50
+ end
51
+
52
+ def run_spec(file_path)
53
+ run "spec #{file_path}"
54
+ end
55
+
56
+ def current_dir
57
+ Dir.tmpdir + "/steak_rspec_1"
58
+ end
59
+
60
+ def steak_dir
61
+ File.expand_path(File.dirname(__FILE__) + "/../../../")
62
+ end
63
+ end
64
+
65
+ RSpec.configure do |config|
66
+ config.include Factories, :example_group => { :file_path => /rspec-1/}
67
+ config.include HelperMethods, :example_group => { :file_path => /rspec-1/}
68
+ config.before :all, :example_group => { :file_path => /rspec-1/} do
69
+ FileUtils.rm_rf current_dir
70
+ FileUtils.mkdir_p current_dir
71
+ File.open(current_dir + "/Gemfile", "w") do |file|
72
+ file.write <<-Gemfile
73
+ source "http://rubygems.org"
74
+ gem "rspec-rails", "~> 1.3.0"
75
+ gem "rails", "~> 2.3.8"
76
+ gem "webrat"
77
+ gem "capybara"
78
+ Gemfile
79
+ end
80
+ Dir.chdir current_dir do
81
+ `rvm gemset create steak-rspec-1`
82
+ `gem install bundler`
83
+ `bundle install`
84
+ end
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+ class String
91
+ CHARS = ('a'..'z').to_a + ('A'..'Z').to_a
92
+ def self.random(size = 8)
93
+ (0..size).map{ CHARS[rand(CHARS.length)] }.join
94
+ end
95
+ end
@@ -5,41 +5,40 @@ feature "Acceptance spec generator for rails", %q{
5
5
  As a developer
6
6
  I want to run a generator that creates it for me
7
7
  } do
8
-
8
+
9
9
  background do
10
10
  @rails_app = create_rails_app
11
11
  end
12
-
12
+
13
13
  scenario "Adding new acceptance spec" do
14
14
  Dir.chdir @rails_app do
15
- `rails generate acceptance_spec document_creation`
15
+ run "script/generate acceptance_spec document_creation"
16
16
  end
17
-
17
+
18
18
  File.exist?(@rails_app + "/spec/acceptance/document_creation_spec.rb").should be_true
19
19
  end
20
-
20
+
21
21
  scenario "Adding new acceptance spec (plural name)" do
22
22
  Dir.chdir @rails_app do
23
- `rails generate acceptance_spec creating_documents`
23
+ run "script/generate acceptance_spec creating_documents"
24
24
  end
25
-
25
+
26
26
  File.exist?(@rails_app + "/spec/acceptance/creating_documents_spec.rb").should be_true
27
27
  end
28
-
28
+
29
29
  scenario "Adding new acceptance spec (pascalized name)" do
30
30
  Dir.chdir @rails_app do
31
- `rails generate acceptance_spec DocumentCreation`
31
+ run "script/generate acceptance_spec DocumentCreation"
32
32
  end
33
-
33
+
34
34
  File.exist?(@rails_app + "/spec/acceptance/document_creation_spec.rb").should be_true
35
35
  end
36
-
36
+
37
37
  scenario "Adding new acceptance spec (name ending with _spec)" do
38
38
  Dir.chdir @rails_app do
39
- `rails generate acceptance_spec document_creation_spec`
39
+ run "script/generate acceptance_spec document_creation_spec"
40
40
  end
41
-
41
+
42
42
  File.exist?(@rails_app + "/spec/acceptance/document_creation_spec.rb").should be_true
43
43
  end
44
-
45
- end
44
+ end
@@ -5,10 +5,10 @@ feature "Acceptance spec execution", %q{
5
5
  As a ruby developer
6
6
  I want to execute acceptance specs
7
7
  } do
8
-
8
+
9
9
  scenario "Minimal acceptance spec" do
10
10
  spec_file = create_spec <<-SPEC
11
- require '#{File.dirname(__FILE__) + "/../../lib/steak"}'
11
+ require '#{File.dirname(__FILE__) + "/../../../lib/steak"}'
12
12
  feature "Minimal spec" do
13
13
  scenario "First scenario" do
14
14
  true.should be_true
@@ -18,10 +18,10 @@ feature "Acceptance spec execution", %q{
18
18
  output = run_spec spec_file
19
19
  output.should =~ /1 example, 0 failures/
20
20
  end
21
-
21
+
22
22
  scenario "Minimal acceptance spec that fails" do
23
23
  spec_file = create_spec <<-SPEC
24
- require '#{File.dirname(__FILE__) + "/../../lib/steak"}'
24
+ require '#{File.dirname(__FILE__) + "/../../../lib/steak"}'
25
25
  feature "Minimal spec" do
26
26
  scenario "First scenario" do
27
27
  true.should be_false
@@ -31,10 +31,10 @@ feature "Acceptance spec execution", %q{
31
31
  output = run_spec spec_file
32
32
  output.should =~ /1 example, 1 failure/
33
33
  end
34
-
34
+
35
35
  scenario "Acceptance spec with background" do
36
36
  spec_file = create_spec <<-SPEC
37
- require '#{File.dirname(__FILE__) + "/../../lib/steak"}'
37
+ require '#{File.dirname(__FILE__) + "/../../../lib/steak"}'
38
38
  feature "Minimal spec" do
39
39
  background do
40
40
  @value = 17
@@ -47,5 +47,4 @@ feature "Acceptance spec execution", %q{
47
47
  output = run_spec spec_file
48
48
  output.should =~ /1 example, 0 failures/
49
49
  end
50
-
51
- end
50
+ end
@@ -5,37 +5,35 @@ feature "Acceptance spec execution", %q{
5
5
  As a rails developer
6
6
  I want to execute acceptance specs
7
7
  } do
8
-
8
+
9
9
  scenario "Minimal acceptance spec" do
10
10
  rails_app = create_rails_app
11
- spec_file = create_spec :path => rails_app + "/spec/acceptance",
11
+ spec_file = create_spec :path => rails_app + "/spec/acceptance",
12
12
  :content => <<-SPEC
13
13
  require File.dirname(__FILE__) + "/acceptance_helper.rb"
14
14
  feature "Minimal spec" do
15
15
  scenario "First scenario" do
16
- # Rails.env.should_not be_nil
17
- Rails.env.should == "test"
16
+ Rails.env.should be_test
18
17
  end
19
18
  end
20
19
  SPEC
21
- output = run_spec spec_file, File.join(File.dirname(spec_file), '../..')
20
+ output = run_spec spec_file
22
21
  output.should =~ /1 example, 0 failures/
23
22
  end
24
-
23
+
25
24
  scenario "Integration stuff" do
26
25
  rails_app = create_rails_app
27
- spec_file = create_spec :path => rails_app + "/spec/acceptance",
26
+ spec_file = create_spec :path => rails_app + "/spec/acceptance",
28
27
  :content => <<-SPEC
29
28
  require File.dirname(__FILE__) + "/acceptance_helper.rb"
30
29
  feature "Minimal spec" do
31
30
  scenario "First scenario" do
32
31
  get "/"
33
- response.should contain(/No route matches/)
32
+ response.should have_text(/No route matches/)
34
33
  end
35
34
  end
36
35
  SPEC
37
- output = run_spec spec_file, File.join(File.dirname(spec_file), '../..')
38
- output.should =~ /1 example, 1 failures/
36
+ output = run_spec spec_file
37
+ output.should =~ /1 example, 0 failures/
39
38
  end
40
-
41
- end
39
+ end
@@ -7,25 +7,23 @@ feature "Steak generator for rails", %q{
7
7
  } do
8
8
 
9
9
  scenario "Running generator in an empty project" do
10
-
11
10
  rails_app = create_rails_app(:setup_steak => false)
12
11
 
13
12
  Dir.chdir rails_app do
14
- `rails generate steak`
13
+ run "script/generate steak"
15
14
  end
16
15
 
17
16
  File.exist?(rails_app + "/spec/acceptance/acceptance_helper.rb").should be_true
18
17
  File.exist?(rails_app + "/spec/acceptance/support/helpers.rb").should be_true
19
18
  File.exist?(rails_app + "/spec/acceptance/support/paths.rb").should be_true
20
19
  File.exist?(rails_app + "/lib/tasks/steak.rake").should be_true
21
-
22
20
  end
23
21
 
24
22
  scenario "Running generator with capybara by default" do
25
- rails_app = create_rails_app(:setup_steak => false, :scaffold => :users)
23
+ rails_app = create_rails_app(:setup_steak => false)
26
24
 
27
25
  Dir.chdir rails_app do
28
- `rails generate steak`
26
+ run "script/generate steak"
29
27
  end
30
28
 
31
29
  spec_file = create_spec :path => rails_app + "/spec/acceptance",
@@ -33,46 +31,45 @@ feature "Steak generator for rails", %q{
33
31
  require File.dirname(__FILE__) + "/acceptance_helper.rb"
34
32
  feature "Capybara spec" do
35
33
  scenario "First scenario" do
36
- visit "/users"
37
- page.should have_content('Listing users')
34
+ visit "/"
35
+ page.should have_content('No route matches')
38
36
  end
39
37
  end
40
38
  SPEC
41
- output = run_spec spec_file, rails_app
39
+ output = run_spec spec_file
42
40
  output.should =~ /1 example, 0 failures/
43
41
  end
44
42
 
45
43
  scenario "Running generator with webrat" do
46
- rails_app = create_rails_app(:setup_steak => false, :scaffold => :users)
44
+ rails_app = create_rails_app(:setup_steak => false)
47
45
 
48
46
  Dir.chdir rails_app do
49
- `rails generate steak --webrat`
47
+ run "script/generate steak --webrat"
50
48
  end
51
49
 
52
50
  spec_file = create_spec :path => rails_app + "/spec/acceptance",
53
51
  :content => <<-SPEC
54
52
  require File.dirname(__FILE__) + "/acceptance_helper.rb"
55
- feature "Webrat spec" do
53
+ feature "Capybara spec" do
56
54
  scenario "First scenario" do
57
- visit "/users"
58
- response_body.should contain('Listing users')
55
+ visit "/"
56
+ response.should contain('No route matches')
59
57
  end
60
58
  end
61
59
  SPEC
62
-
63
- output = run_spec spec_file, rails_app
60
+ output = run_spec spec_file
64
61
  output.should =~ /1 example, 0 failures/
65
62
  end
66
-
63
+
67
64
  scenario "Running rake stats" do
68
65
  rails_app = create_rails_app
69
66
 
70
67
  Dir.chdir rails_app do
71
- `rails generate steak`
72
- `rake stats`.should =~ /Acceptance specs/
68
+ run "script/generate steak"
69
+ run("rake stats").should =~ /Acceptance specs/
73
70
  end
74
71
  end
75
-
72
+
76
73
  scenario "Running specs with rake" do
77
74
  rails_app = create_rails_app(:setup_steak => true)
78
75
 
@@ -85,16 +82,15 @@ feature "Steak generator for rails", %q{
85
82
  end
86
83
  end
87
84
  SPEC
88
-
85
+
89
86
  Dir.chdir rails_app do
90
- `rake db:create db:migrate db:test:prepare`
91
-
92
- output = `rake spec:acceptance`
87
+ run "rake db:migrate db:test:prepare"
88
+
89
+ output = run "rake spec:acceptance"
93
90
  output.should =~ /1 example, 0 failures/
94
-
95
- output = `rake`
91
+
92
+ output = run "rake"
96
93
  output.should =~ /1 example, 0 failures/
97
94
  end
98
95
  end
99
-
100
96
  end