spork 0.5.8 → 0.5.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -39,11 +39,11 @@ Feature: Cucumber integration with rails
39
39
 
40
40
  Spork.each_run do
41
41
  # This code will be run each time you run your specs.
42
- require 'cucumber/rails/world'
42
+
43
43
  Cucumber::Rails.use_transactional_fixtures
44
44
  Cucumber::Rails.bypass_rescue # Comment out this line if you want Rails own error handling
45
45
  # (e.g. rescue_action_in_public / rescue_responses / rescue_from)
46
-
46
+
47
47
  #### this is for this test only #######
48
48
  $loaded_stuff << 'each_run block' #####
49
49
  #######################################
@@ -52,8 +52,18 @@ Feature: Cucumber integration with rails
52
52
  And a file named "features/cucumber_rails.feature" with:
53
53
  """
54
54
  Feature: cucumber rails
55
- Scenario: did it work
55
+ Scenario: did it work?
56
56
  Then it should work
57
+
58
+ Scenario: did it work again?
59
+ Then it should work
60
+ """
61
+ And a file named "features/cucumber_rails_fr.feature" with:
62
+ """
63
+ # language: fr
64
+ Fonction: French
65
+ Scénario: ca marche?
66
+ Alors ca marche
57
67
  """
58
68
  And a file named "features/support/cucumber_rails_helper.rb" with:
59
69
  """
@@ -73,8 +83,6 @@ Feature: Cucumber integration with rails
73
83
  And a file named "features/step_definitions/cucumber_rails_steps.rb" with:
74
84
  """
75
85
  Then "it should work" do
76
- Spork.state.should == :using_spork
77
- RAILS_ENV.should == 'features'
78
86
  (Rails.respond_to?(:logger) ? Rails.logger : ActionController::Base.logger).info "hey there"
79
87
  $loaded_stuff.should include('ActiveRecord::Base.establish_connection')
80
88
  $loaded_stuff.should include('User')
@@ -86,6 +94,9 @@ Feature: Cucumber integration with rails
86
94
  $loaded_stuff.should include('prefork block')
87
95
  puts "It worked!"
88
96
  end
97
+
98
+ Alors /ca marche/ do
99
+ end
89
100
  """
90
101
  Scenario: Analyzing files were preloaded
91
102
  When I run spork --diagnose
@@ -98,9 +109,23 @@ Feature: Cucumber integration with rails
98
109
  Then the output should not contain "features/step_definitions/cucumber_rails_steps.rb"
99
110
  Then the output should not contain "features/support/cucumber_rails_helper.rb"
100
111
 
112
+ Scenario: Running spork with a rails app and no server
113
+ When I run cucumber --drb features
114
+ Then the error output should contain
115
+ """
116
+ WARNING: No DRb server is running. Running features locally
117
+ """
118
+
101
119
  Scenario: Running spork with a rails app and observers
102
120
  When I fire up a spork instance with "spork cucumber"
103
- And I run cucumber --drb features/cucumber_rails.feature
104
- Then the output should contain "It worked!"
121
+ And I run cucumber --drb features
122
+ Then the error output should be empty
123
+ And the output should contain "It worked!"
124
+ And the file "log/features.log" should include "hey there"
125
+
126
+ Scenario: Running spork with a rails app and a non-standard port
127
+ When I fire up a spork instance with "spork cucumber -p 9000"
128
+ And I run cucumber --drb --port 9000 features
129
+ Then the error output should be empty
130
+ And the output should contain "It worked!"
105
131
  And the file "log/features.log" should include "hey there"
106
-
@@ -30,7 +30,11 @@ Feature: Diagnostic Mode
30
30
  end
31
31
  """
32
32
  When I run spork --diagnose
33
- Then the output should contain "lib/awesome.rb"
33
+ Then the error output should contain
34
+ """
35
+ Loading Spork.prefork block...
36
+ """
37
+ And the output should contain "lib/awesome.rb"
34
38
  And the output should contain "spec/spec_helper.rb:5"
35
39
  And the output should not contain "super_duper.rb"
36
40
  And the output should not contain "diagnose.rb"
@@ -62,5 +62,31 @@ Feature: Rails Integration
62
62
  """
63
63
  When I fire up a spork instance with "spork rspec"
64
64
  And I run spec --drb spec/did_it_work_spec.rb
65
- Then the output should contain "Specs successfully run within spork, and all initialization files were loaded"
65
+ Then the error output should be empty
66
+ And the output should contain "Specs successfully run within spork, and all initialization files were loaded"
67
+ And the file "log/test.log" should include "hey there"
68
+
69
+
70
+ Scenario: Running spork with a rails app and a non-standard port
71
+ Given a file named "spec/did_it_work_spec.rb" with:
72
+ """
73
+ describe "Did it work?" do
74
+ it "checks to see if all worked" do
75
+ Spork.state.should == :using_spork
76
+ (Rails.respond_to?(:logger) ? Rails.logger : ActionController::Base.logger).info "hey there"
77
+ $loaded_stuff.should include('ActiveRecord::Base.establish_connection')
78
+ $loaded_stuff.should include('User')
79
+ $loaded_stuff.should include('UserObserver')
80
+ $loaded_stuff.should include('ApplicationHelper')
81
+ $loaded_stuff.should include('config/routes.rb')
82
+ $loaded_stuff.should include('each_run block')
83
+ $loaded_stuff.should include('prefork block')
84
+ puts "Specs successfully run within spork, and all initialization files were loaded"
85
+ end
86
+ end
87
+ """
88
+ When I fire up a spork instance with "spork rspec --port 7000"
89
+ And I run spec --drb --port 7000 spec/did_it_work_spec.rb
90
+ Then the error output should be empty
91
+ And the output should contain "Specs successfully run within spork, and all initialization files were loaded"
66
92
  And the file "log/test.log" should include "hey there"
@@ -2,7 +2,7 @@ Given /^I am in a fresh rails project named "(.+)"$/ do |folder_name|
2
2
  @current_dir = SporkWorld::SANDBOX_DIR
3
3
  version_argument = ENV['RAILS_VERSION'] ? "_#{ENV['RAILS_VERSION']}_" : nil
4
4
  # run("#{SporkWorld::RUBY_BINARY} #{%x{which rails}.chomp} #{folder_name}")
5
- run([SporkWorld::RUBY_BINARY, %x{which rails}.chomp, version_argument, folder_name].compact * " ")
5
+ run([SporkWorld::RUBY_BINARY, '-I', Cucumber::LIBDIR, %x{which rails}.chomp, version_argument, folder_name].compact * " ")
6
6
  @current_dir = File.join(File.join(SporkWorld::SANDBOX_DIR, folder_name))
7
7
  end
8
8
 
@@ -34,16 +34,19 @@ Given /^the following code appears in "([^\"]*)" after \/([^\\\/]*)\/:$/ do |fil
34
34
  end
35
35
 
36
36
  When /^I run (spork|spec|cucumber)($| .*$)/ do |command, spork_opts|
37
- if command == 'spork'
37
+ case command
38
+ when 'spork'
38
39
  command = SporkWorld::BINARY
40
+ when 'cucumber'
41
+ command = Cucumber::BINARY
39
42
  else
40
43
  command = %x{which #{command}}.chomp
41
44
  end
42
- run "#{SporkWorld::RUBY_BINARY} #{command} #{spork_opts}"
45
+ run "#{SporkWorld::RUBY_BINARY} -I #{Cucumber::LIBDIR} #{command} #{spork_opts}"
43
46
  end
44
47
 
45
48
  When /^I fire up a spork instance with "spork(.*)"$/ do |spork_opts|
46
- run_in_background "#{SporkWorld::RUBY_BINARY} #{SporkWorld::BINARY} #{spork_opts}"
49
+ run_in_background "#{SporkWorld::RUBY_BINARY} -I #{Cucumber::LIBDIR} #{SporkWorld::BINARY} #{spork_opts}"
47
50
  output = ""
48
51
  begin
49
52
  status = Timeout::timeout(15) do
@@ -86,6 +89,10 @@ Then /^the (error output|output) should not contain "(.+)"$/ do |which, text|
86
89
  (which == "error output" ? last_stderr : last_stdout).should_not include(text)
87
90
  end
88
91
 
92
+ Then /^the (error output|output) should be empty$/ do |which|
93
+ (which == "error output" ? last_stderr : last_stdout).should == ""
94
+ end
95
+
89
96
  Then /^the (error output|output) should be$/ do |which, text|
90
97
  (which == "error output" ? last_stderr : last_stdout).should == text
91
98
  end
@@ -4,10 +4,11 @@ require 'forwardable'
4
4
  require 'tempfile'
5
5
  require 'spec/expectations'
6
6
  require 'timeout'
7
+ require 'spork'
7
8
 
8
9
  class SporkWorld
9
- RUBY_BINARY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
10
10
  BINARY = File.expand_path(File.dirname(__FILE__) + '/../../bin/spork')
11
+ RUBY_BINARY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
11
12
  SANDBOX_DIR = File.expand_path(File.join(File.dirname(__FILE__), '../../tmp/sandbox'))
12
13
 
13
14
  extend Forwardable
@@ -1,5 +1,8 @@
1
1
  $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
2
2
  module Spork
3
+ BINARY = File.expand_path(File.dirname(__FILE__) + '/../bin/spork')
4
+ LIBDIR = File.expand_path(File.dirname(__FILE__))
5
+
3
6
  class << self
4
7
  # 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.
5
8
  #
@@ -22,6 +22,7 @@ module Spork
22
22
  opt.on("-b", "--bootstrap") {|ignore| @options[:bootstrap] = true }
23
23
  opt.on("-d", "--diagnose") {|ignore| @options[:diagnose] = true }
24
24
  opt.on("-h", "--help") {|ignore| @options[:help] = true }
25
+ opt.on("-p", "--port [PORT]") {|port| @options[:port] = port }
25
26
  non_option_args = args.select { |arg| ! args[0].match(/^-/) }
26
27
  @options[:server_matcher] = non_option_args[0]
27
28
  opt.parse!(args)
@@ -81,6 +82,9 @@ Are you running me from a project directory?
81
82
  ENV["DRB"] = 'true'
82
83
  @error.puts "Using #{server.server_name}"
83
84
  @error.flush
85
+
86
+ server.port = options[:port]
87
+
84
88
  case
85
89
  when options[:bootstrap]
86
90
  server.bootstrap
@@ -94,7 +94,11 @@ class Spork::Server
94
94
  end
95
95
 
96
96
  def port
97
- self.class.port
97
+ self.class.instance_variable_get("@port") || self.class.port
98
+ end
99
+
100
+ def self.port= p
101
+ @port = p
98
102
  end
99
103
 
100
104
  def helper_file
@@ -194,4 +198,4 @@ class Spork::Server
194
198
  end
195
199
  end
196
200
 
197
- Dir[File.dirname(__FILE__) + "/server/*.rb"].each { |file| require file }
201
+ Dir[File.dirname(__FILE__) + "/server/*.rb"].each { |file| require file }
@@ -1,34 +1,35 @@
1
+ require 'cucumber'
2
+
1
3
  class Spork::Server::Cucumber < Spork::Server
2
4
  CUCUMBER_PORT = 8990
3
5
  CUCUMBER_HELPER_FILE = File.join(Dir.pwd, "features/support/env.rb")
4
6
 
5
7
  class << self
6
8
  def port
7
- CUCUMBER_PORT
9
+ (ENV['CUCUMBER_DRB'] || CUCUMBER_PORT).to_i
8
10
  end
9
11
 
10
12
  def helper_file
11
13
  CUCUMBER_HELPER_FILE
12
14
  end
13
15
 
14
- # REMOVE WHEN SUPPORT FOR PRE-0.4 IS DROPPED
16
+ # REMOVE WHEN SUPPORT FOR 0.3.95 AND EARLIER IS DROPPED
15
17
  attr_accessor :step_mother
16
18
  end
17
19
 
18
- # REMOVE WHEN SUPPORT FOR PRE-0.4 IS DROPPED
20
+ # REMOVE WHEN SUPPORT FOR 0.3.95 AND EARLIER IS DROPPED
19
21
  def step_mother
20
22
  self.class.step_mother
21
23
  end
22
24
 
23
25
  def run_tests(argv, stderr, stdout)
24
- begin
25
- require 'cucumber/cli/main'
26
- ::Cucumber::Cli::Main.new(argv, stdout, stderr).execute!(::Cucumber::StepMother.new)
27
- rescue NoMethodError => pre_cucumber_0_4 # REMOVE WHEN SUPPORT FOR PRE-0.4 IS DROPPED
28
- ::Cucumber::Cli::Main.step_mother = step_mother
29
- ::Cucumber::Cli::Main.new(argv, stdout, stderr).execute!(step_mother)
30
- end
26
+ ::Cucumber::Cli::Main.new(argv, stdout, stderr).execute!(step_mother)
31
27
  end
32
28
  end
33
29
 
34
- Spork::Server::Cucumber.step_mother = self # REMOVE WHEN SUPPORT FOR PRE-0.4 IS DROPPED
30
+ begin
31
+ Spork::Server::Cucumber.step_mother = ::Cucumber::StepMother.new
32
+ Spork::Server::Cucumber.step_mother.load_programming_language('rb') if defined?(Spork::Server)
33
+ rescue NoMethodError => pre_cucumber_0_4 # REMOVE WHEN SUPPORT FOR 0.3.95 AND EARLIER IS DROPPED
34
+ Spork::Server::Cucumber.step_mother = self
35
+ end
@@ -3,7 +3,7 @@ class Spork::Server::RSpec < Spork::Server
3
3
  RSPEC_HELPER_FILE = File.join(Dir.pwd, "spec/spec_helper.rb")
4
4
 
5
5
  def self.port
6
- RSPEC_PORT
6
+ (ENV['RSPEC_DRB'] || RSPEC_PORT).to_i
7
7
  end
8
8
 
9
9
  def self.helper_file
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Spork::Server::Cucumber do
4
+ before(:each) do
5
+ @server = Spork::Server::Cucumber.new
6
+ end
7
+
8
+ it "uses the CUCUMBER_PORT for it's default port" do
9
+ @server.port.should == Spork::Server::Cucumber::CUCUMBER_PORT
10
+ end
11
+
12
+ it "uses ENV['CUCUMBER_DRB'] as port if present" do
13
+ orig = ENV['CUCUMBER_DRB']
14
+ begin
15
+ ENV['CUCUMBER_DRB'] = "9000"
16
+ @server.port.should == 9000
17
+ ensure
18
+ ENV['CUCUMBER_DRB'] = orig
19
+ end
20
+ end
21
+
22
+ it "uses the CUCUMBER_HELPER_FILE for it's helper_file" do
23
+ @server.helper_file.should == Spork::Server::Cucumber::CUCUMBER_HELPER_FILE
24
+ end
25
+ end
@@ -5,9 +5,19 @@ describe Spork::Server::RSpec do
5
5
  @server = Spork::Server::RSpec.new
6
6
  end
7
7
 
8
- it "uses the RSPEC_PORT for it's port" do
8
+ it "uses the RSPEC_PORT for it's default port" do
9
9
  @server.port.should == Spork::Server::RSpec::RSPEC_PORT
10
10
  end
11
+
12
+ it "uses ENV['RSPEC_DRB'] as port if present" do
13
+ orig = ENV['RSPEC_DRB']
14
+ begin
15
+ ENV['RSPEC_DRB'] = "9000"
16
+ @server.port.should == 9000
17
+ ensure
18
+ ENV['RSPEC_DRB'] = orig
19
+ end
20
+ end
11
21
 
12
22
  it "uses the RSPEC_HELPER_FILE for it's helper_file" do
13
23
  @server.helper_file.should == Spork::Server::RSpec::RSPEC_HELPER_FILE
@@ -124,5 +124,18 @@ describe Spork::Server do
124
124
  @fake.stub!(:run_tests).and_return("tests were ran")
125
125
  @fake.run("test", STDOUT, STDIN).should == "tests were ran"
126
126
  end
127
+
128
+ it "accepts a port" do
129
+ create_helper_file
130
+ @fake.class.port = 12345
131
+ @fake.port.should == 12345
132
+ end
133
+
134
+ it "falls back to a default port" do
135
+ create_helper_file
136
+ @fake.class.port = nil
137
+ @fake.port.should == FakeServer.port
138
+ end
139
+
127
140
  end
128
141
  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.5.8
4
+ version: 0.5.9
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-08-13 00:00:00 -06:00
12
+ date: 2009-08-19 00:00:00 -06:00
13
13
  default_executable: spork
14
14
  dependencies: []
15
15
 
@@ -56,6 +56,7 @@ files:
56
56
  - spec/spork/diagnoser_spec.rb
57
57
  - spec/spork/forker_spec.rb
58
58
  - spec/spork/runner_spec.rb
59
+ - spec/spork/server/cucumber_spec.rb
59
60
  - spec/spork/server/rspec_spec.rb
60
61
  - spec/spork/server_spec.rb
61
62
  - spec/spork_spec.rb
@@ -96,6 +97,7 @@ test_files:
96
97
  - spec/spork/diagnoser_spec.rb
97
98
  - spec/spork/forker_spec.rb
98
99
  - spec/spork/runner_spec.rb
100
+ - spec/spork/server/cucumber_spec.rb
99
101
  - spec/spork/server/rspec_spec.rb
100
102
  - spec/spork/server_spec.rb
101
103
  - spec/spork_spec.rb