spork 0.7.3 → 0.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,13 +20,6 @@ Feature: Cucumber integration with rails
20
20
  ENV['RAILS_ENV'] = "features"
21
21
  require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
22
22
 
23
- require 'webrat'
24
-
25
- Webrat.configure do |config|
26
- config.mode = :rails
27
- end
28
-
29
- require 'webrat/core/matchers'
30
23
  require 'cucumber'
31
24
  require 'cucumber/formatter/unicode' # Comment out this line if you don't want Cucumber Unicode support
32
25
  require 'spec/rails'
@@ -21,7 +21,6 @@ Feature: Rails Delayed Work arounds
21
21
  end
22
22
  """
23
23
  And the application has a model, observer, route, and application helper
24
- Scenario: within a view, calling helper methods from an included module in ApplicationHelper
25
24
  Given a file named "app/helpers/application_helper.rb" with:
26
25
  """
27
26
  module ApplicationHelper
@@ -45,25 +44,55 @@ Feature: Rails Delayed Work arounds
45
44
  end
46
45
  end
47
46
  """
48
- Given a file named "app/controllers/users_helper.rb" with:
47
+ Given a file named "app/helpers/misc_helper.rb" with:
48
+ """
49
+ module MiscHelper
50
+ def misc_helper_method
51
+ 'hello miscellaneous'
52
+ end
53
+ end
54
+ """
55
+ Given a file named "app/helpers/users_helper.rb" with:
49
56
  """
50
57
  module UsersHelper
51
58
  end
52
59
  """
53
60
  Given a file named "app/views/users/index.html.erb" with:
54
61
  """
55
- <%= reverse_text('listing users'.reverse) %>
62
+ Original View
56
63
  """
64
+ Scenario: within a view rendered by a controller, calling helper methods from an included module in ApplicationHelper
57
65
  Given a file named "spec/controllers/users_controller_spec.rb" with:
58
66
  """
59
67
  describe UsersController do
60
68
  integrate_views
61
69
  it "renders a page, using a method inherited from ApplicationController" do
62
70
  get :index
71
+ response.body.should_not include('Original View')
72
+ puts "Views are not being cached when rendering from a controller"
73
+
74
+ response.body.should include('listing users')
75
+ puts "Controller stack is functioning when rendering from a controller"
76
+
77
+ response.body.should include('hello miscellaneous')
78
+ puts "All helper modules were included when rendering from a controller"
79
+ end
80
+ end
81
+ """
82
+ Given a file named "spec/views/index.html.erb_spec.rb" with:
83
+ """
84
+ describe "/users/index.html.erb" do
85
+
86
+ it "renders the view" do
87
+ render
88
+ response.body.should_not include('Original View')
89
+ puts "Views are not being cached when rendering directly"
90
+
63
91
  response.body.should include('listing users')
64
- puts "Controller stack is functioning"
65
- response.body.should include('Here is a list of users')
66
- puts "Views are not being cached"
92
+ puts "Controller stack is functioning when rendering directly"
93
+
94
+ response.body.should include('hello miscellaneous')
95
+ puts "All helper modules were included when rendering directly"
67
96
  end
68
97
  end
69
98
  """
@@ -71,10 +100,16 @@ Feature: Rails Delayed Work arounds
71
100
  And the contents of "app/views/users/index.html.erb" are changed to:
72
101
  """
73
102
  <%= reverse_text('listing users'.reverse) %>
103
+ <%= misc_helper_method rescue nil %>
74
104
  <p>Here is a list of users</p>
75
105
  """
76
106
 
77
107
  And I run spec --drb spec/controllers/users_controller_spec.rb
78
- Then the output should contain "Controller stack is functioning"
79
- Then the output should contain "Views are not being cached"
80
-
108
+ Then the output should contain "Controller stack is functioning when rendering from a controller"
109
+ Then the output should contain "Views are not being cached when rendering from a controller"
110
+ Then the output should contain "All helper modules were included when rendering from a controller"
111
+
112
+ And I run spec --drb spec/views/index.html.erb_spec.rb
113
+ Then the output should contain "Controller stack is functioning when rendering directly"
114
+ Then the output should contain "Views are not being cached when rendering directly"
115
+ Then the output should contain "All helper modules were included when rendering directly"
@@ -3,24 +3,17 @@ Feature: Spork Debugger integration
3
3
  I want to invoke the debugger my specs within Spork
4
4
  In order to drill in and figure out what's wrong
5
5
 
6
- Background: Rails App with RSpec and Spork
7
-
6
+ Scenario: Invoking the debugger via 'debugger'
8
7
  Given a file named "spec/spec_helper.rb" with:
9
8
  """
10
9
  require 'rubygems'
11
10
  require 'spork'
12
11
  require 'spork/ext/ruby-debug'
13
12
 
14
- Spork.prefork do
15
- require 'spec'
16
- end
17
-
18
- Spork.each_run do
19
- end
13
+ Spork.prefork { require 'spec' }
14
+ Spork.each_run { }
20
15
  """
21
-
22
- Scenario: Invoking the debugger via 'debugger'
23
- Given a file named "spec/debugger_spec.rb" with:
16
+ And a file named "spec/debugger_spec.rb" with:
24
17
  """
25
18
  require File.dirname(__FILE__) + '/spec_helper.rb'
26
19
 
@@ -55,12 +48,23 @@ Feature: Spork Debugger integration
55
48
  And the output should contain "it worked!"
56
49
 
57
50
  Scenario: When ruby-debug is already required and started.
58
- Given a file named "spec/debugger_spec.rb" with:
51
+ Given a file named "spec/spec_helper.rb" with:
59
52
  """
60
- require File.dirname(__FILE__) + '/spec_helper.rb'
53
+ require 'rubygems'
54
+ require 'spork'
61
55
  require 'ruby-debug'
62
56
  Debugger.start
63
57
 
58
+ require 'spork/ext/ruby-debug'
59
+
60
+ Spork.prefork { require 'spec' }
61
+ Spork.each_run { }
62
+ """
63
+
64
+ And a file named "spec/debugger_spec.rb" with:
65
+ """
66
+ require File.dirname(__FILE__) + '/spec_helper.rb'
67
+
64
68
  describe "Debugger" do
65
69
  it "should debug" do
66
70
  @message = "yup"
@@ -82,3 +86,23 @@ Feature: Spork Debugger integration
82
86
 
83
87
  Then the spork window should output a line containing "Debug Session Terminated"
84
88
  And the output should contain "it worked!"
89
+
90
+ Scenario: When ruby-debug is invoked during preload
91
+ Given a file named "spec/spec_helper.rb" with:
92
+ """
93
+ require 'rubygems'
94
+ require 'spork'
95
+ require 'spork/ext/ruby-debug'
96
+
97
+ STDERR.puts("Spork is ready and listening") # trick out the start spork step to believe spork is ready... naughty, but effective.
98
+ @message = "it worked"
99
+ debugger
100
+ Spork.prefork { require 'spec' }
101
+ Spork.each_run { }
102
+ """
103
+
104
+ When I fire up a spork instance with "spork rspec"
105
+ Then the spork window should output a line containing "spec_helper.rb"
106
+ When I type this in the spork window: "e @message"
107
+ Then the spork window should output a line containing "it worked"
108
+ When I type this in the spork window: "continue"
@@ -18,8 +18,6 @@ end
18
18
 
19
19
  # the following code appears in "config/environment.rb" after /Rails::Initializer.run/:
20
20
  Given /^the following code appears in "([^\"]*)" after \/([^\\\/]*)\/:$/ do |file_name, regex, content|
21
- # require 'ruby-debug'; Debugger.start; Debugger.start_control; debugger
22
-
23
21
  regex = Regexp.new(regex)
24
22
  in_current_dir do
25
23
  content_lines = File.read(file_name).split("\n")
@@ -6,4 +6,4 @@ gems:
6
6
  - { name: 'rspec', version: '>= 1.2.9' }
7
7
  - { name: 'rspec-rails', version: '>= 1.2.9' }
8
8
  - { name: 'rails', version: '>= 2.3' }
9
-
9
+ - { name: 'ruby-debug', version: '>= 0.10.3' }
@@ -1,7 +1,16 @@
1
1
  $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
2
+ require 'pathname'
2
3
  module Spork
3
4
  BINARY = File.expand_path(File.dirname(__FILE__) + '/../bin/spork')
4
- LIBDIR = File.expand_path("..", File.dirname(__FILE__))
5
+ LIBDIR = Pathname.new(File.expand_path(File.dirname(__FILE__)))
6
+
7
+ autoload :Server, (LIBDIR + 'spork/server').to_s
8
+ autoload :TestFramework, (LIBDIR + 'spork/test_framework').to_s
9
+ autoload :AppFramework, (LIBDIR + 'spork/app_framework').to_s
10
+ autoload :RunStrategy, (LIBDIR + 'spork/run_strategy').to_s
11
+ autoload :Runner, (LIBDIR + 'spork/runner').to_s
12
+ autoload :Forker, (LIBDIR + 'spork/forker').to_s
13
+ autoload :Diagnoser, (LIBDIR + 'spork/diagnoser').to_s
5
14
 
6
15
  class << self
7
16
  # Run a block, during prefork mode. By default, if prefork is called twice in the same file and line number, the supplied block will only be ran once.
@@ -75,11 +84,19 @@ module Spork
75
84
  end
76
85
 
77
86
  def detect_and_require(subfolder)
78
- ([LIBDIR] + Gem.latest_load_paths.grep(/spork/)).uniq.each do |gem_path|
87
+ ([LIBDIR.to_s] + other_spork_gem_load_paths).uniq.each do |gem_path|
79
88
  Dir.glob(File.join(gem_path, subfolder)).each { |file| require file }
80
89
  end
81
90
  end
82
91
 
92
+ def other_spork_gem_load_paths
93
+ @other_spork_gem_load_paths ||= (
94
+ Gem.latest_load_paths.grep(/spork/).select do |g|
95
+ not g.match(%r{/spork-[0-9\-.]+/lib}) # don't include other versions of spork
96
+ end
97
+ )
98
+ end
99
+
83
100
  private
84
101
  def alias_method_names(method_name, feature)
85
102
  /^(.+?)([\?\!]{0,1})$/.match(method_name.to_s)
@@ -1,3 +1 @@
1
- # This is a stub used to help Spork delay the loading of the real ApplicationController
2
- class ::ApplicationController < ActionController::Base
3
- end
1
+ load(File.dirname(__FILE__) + "/application_controller.rb")
@@ -1,3 +1,22 @@
1
1
  # This is a stub used to help Spork delay the loading of the real ApplicationController
2
2
  class ::ApplicationController < ActionController::Base
3
+ @@preloading = true
4
+ class << self
5
+ def inherited(klass)
6
+ (@_descendants ||= []) << klass if @@preloading
7
+ super
8
+ end
9
+
10
+ def reapply_inheritance!
11
+ @@preloading = false
12
+ @_descendants.each do |descendant|
13
+ descendant.master_helper_module.send(:include, master_helper_module)
14
+ descendant.send(:default_helper_module!)
15
+
16
+ descendant.respond_to?(:reapply_inheritance) && descendant.reapply_inheritance!
17
+ end
18
+ end
19
+ end
3
20
  end
21
+
22
+ Spork.each_run { ApplicationController.reapply_inheritance! }
@@ -1,8 +1,10 @@
1
- require 'ruby-debug'
2
1
  require 'socket'
3
2
  require 'forwardable'
4
3
 
5
- # Experimental! No automated tests are checking this, use at your own risk!
4
+ begin
5
+ require 'ruby-debug'
6
+
7
+ # Experimental!
6
8
 
7
9
  class SporkDebugger
8
10
  DEFAULT_PORT = 10_123
@@ -15,7 +17,7 @@ class SporkDebugger
15
17
  class << self
16
18
  attr_reader :instance
17
19
  def run
18
- @instance = new
20
+ @instance ||= new
19
21
  end
20
22
  end
21
23
 
@@ -44,7 +46,7 @@ class SporkDebugger
44
46
  class PreloadState
45
47
  include NetworkHelpers
46
48
  def initialize
47
- install_hook
49
+ Spork.each_run { install_hook }
48
50
  listen_for_connection_signals
49
51
  end
50
52
 
@@ -143,3 +145,6 @@ end
143
145
 
144
146
  Spork.prefork { SporkDebugger.run } if Spork.using_spork?
145
147
 
148
+ rescue LoadError
149
+ raise LoadError, "Your project has loaded spork/ext/ruby-debug, which relies on the ruby-debug gem. It appears that ruby-debug is not installed. Please install it."
150
+ end
@@ -1,7 +1,4 @@
1
1
  require 'optparse'
2
- require 'spork/server'
3
- require 'spork/test_framework'
4
- require 'spork/run_strategy'
5
2
 
6
3
  module Spork
7
4
  # This is used by bin/spork. It's wrapped in a class because it's easier to test that way.
@@ -72,6 +69,7 @@ module Spork
72
69
  Spork::Diagnoser.output_results(@output)
73
70
  return true
74
71
  else
72
+ Spork.using_spork!
75
73
  run_strategy = Spork::RunStrategy.factory(test_framework)
76
74
  return(false) unless run_strategy.preload
77
75
  Spork::Server.run(:port => @options[:port] || test_framework.default_port, :run_strategy => run_strategy)
@@ -22,6 +22,7 @@ class Spork::Server
22
22
 
23
23
  # Sets up signals and starts the DRb service. If it's successful, it doesn't return. Not ever. You don't need to override this.
24
24
  def listen
25
+ raise RuntimeError, "you must call Spork.using_spork! before starting the server" unless Spork.using_spork?
25
26
  trap("SIGINT") { sig_int_received }
26
27
  trap("SIGTERM") { abort; exit!(0) }
27
28
  trap("USR2") { abort; restart } if Signal.list.has_key?("USR2")
@@ -5,10 +5,7 @@ unless $spec_helper_loaded
5
5
 
6
6
  $LOAD_PATH.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
7
7
  SPEC_TMP_DIR = File.expand_path('tmp', File.dirname(__FILE__))
8
-
9
8
  require 'spork'
10
- require 'spork/runner.rb'
11
- require 'spork/diagnoser.rb'
12
9
  require 'stringio'
13
10
  require 'fileutils'
14
11
 
@@ -45,13 +45,6 @@ describe Spork::Runner do
45
45
  Spork::TestFramework::RSpec.stub!(:available?).and_return(true)
46
46
  Spork::TestFramework::Cucumber.stub!(:available?).and_return(false)
47
47
 
48
- Spork::Runner.new(['rspec'], @out, @err).supported_test_frameworks_text.should == <<-EOF
49
- Supported test frameworks:
50
- ( ) Cucumber
51
- ( ) FakeFramework
52
- (*) RSpec
53
-
54
- Legend: ( ) - not detected in project (*) - detected
55
- EOF
48
+ Spork::Runner.new(['rspec'], @out, @err).supported_test_frameworks_text.should include("(*) RSpec")
56
49
  end
57
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spork
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Harper
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-12 00:00:00 -06:00
12
+ date: 2009-12-04 00:00:00 -07:00
13
13
  default_executable: spork
14
14
  dependencies: []
15
15