milhouse-spork 0.7.5.1 → 0.7.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/MIT-LICENSE +19 -19
  2. data/README.rdoc +99 -99
  3. data/assets/bootstrap.rb +29 -29
  4. data/bin/spork +20 -20
  5. data/features/cucumber_rails_integration.feature +118 -118
  6. data/features/diagnostic_mode.feature +40 -40
  7. data/features/rails_delayed_loading_workarounds.feature +115 -115
  8. data/features/rspec_rails_integration.feature +93 -93
  9. data/features/spork_debugger.feature +108 -108
  10. data/features/steps/general_steps.rb +3 -3
  11. data/features/steps/rails_steps.rb +52 -52
  12. data/features/steps/sandbox_steps.rb +115 -115
  13. data/features/support/background_job.rb +63 -63
  14. data/features/support/env.rb +111 -111
  15. data/features/unknown_app_framework.feature +41 -41
  16. data/geminstaller.yml +9 -9
  17. data/lib/spork/app_framework/rails.rb +157 -157
  18. data/lib/spork/app_framework/rails_stub_files/application.rb +1 -1
  19. data/lib/spork/app_framework/rails_stub_files/application_controller.rb +22 -22
  20. data/lib/spork/app_framework/rails_stub_files/application_helper.rb +2 -2
  21. data/lib/spork/app_framework/unknown.rb +5 -5
  22. data/lib/spork/app_framework.rb +73 -73
  23. data/lib/spork/custom_io_streams.rb +24 -24
  24. data/lib/spork/diagnoser.rb +103 -103
  25. data/lib/spork/ext/ruby-debug.rb +150 -150
  26. data/lib/spork/forker.rb +70 -70
  27. data/lib/spork/run_strategy/forking.rb +29 -29
  28. data/lib/spork/run_strategy/magazine/magazine_slave.rb +0 -0
  29. data/lib/spork/run_strategy/magazine/magazine_slave_provider.rb +0 -0
  30. data/lib/spork/run_strategy/magazine/ring_server.rb +0 -0
  31. data/lib/spork/run_strategy/magazine.rb +2 -2
  32. data/lib/spork/run_strategy.rb +44 -44
  33. data/lib/spork/runner.rb +90 -90
  34. data/lib/spork/server.rb +74 -74
  35. data/lib/spork/test_framework/cucumber.rb +24 -24
  36. data/lib/spork/test_framework/rspec.rb +14 -14
  37. data/lib/spork/test_framework.rb +167 -167
  38. data/lib/spork.rb +126 -126
  39. data/spec/spec_helper.rb +108 -108
  40. data/spec/spork/app_framework/rails_spec.rb +22 -22
  41. data/spec/spork/app_framework/unknown_spec.rb +12 -12
  42. data/spec/spork/app_framework_spec.rb +16 -16
  43. data/spec/spork/diagnoser_spec.rb +105 -105
  44. data/spec/spork/forker_spec.rb +44 -44
  45. data/spec/spork/run_strategy/forking_spec.rb +38 -38
  46. data/spec/spork/runner_spec.rb +50 -50
  47. data/spec/spork/server_spec.rb +15 -15
  48. data/spec/spork/test_framework/cucumber_spec.rb +11 -11
  49. data/spec/spork/test_framework/rspec_spec.rb +10 -10
  50. data/spec/spork/test_framework_spec.rb +114 -114
  51. data/spec/spork_spec.rb +151 -151
  52. data/spec/support/fake_framework.rb +15 -15
  53. data/spec/support/fake_run_strategy.rb +21 -21
  54. metadata +7 -15
@@ -1,53 +1,53 @@
1
- Given /^I am in a fresh rails project named "(.+)"$/ do |folder_name|
2
- @current_dir = SporkWorld::SANDBOX_DIR
3
- version_argument = ENV['RAILS_VERSION'] ? "_#{ENV['RAILS_VERSION']}_" : nil
4
- # run("#{SporkWorld::RUBY_BINARY} #{%x{which rails}.chomp} #{folder_name}")
5
- run([SporkWorld::RUBY_BINARY, '-I', Cucumber::LIBDIR, %x{which rails}.chomp, version_argument, folder_name].compact * " ")
6
- @current_dir = File.join(File.join(SporkWorld::SANDBOX_DIR, folder_name))
7
- end
8
-
9
-
10
- Given "the application has a model, observer, route, and application helper" do
11
- Given 'a file named "app/models/user.rb" with:',
12
- """
13
- class User < ActiveRecord::Base
14
- $loaded_stuff << 'User'
15
- end
16
- """
17
- Given 'a file named "app/models/user_observer.rb" with:',
18
- """
19
- class UserObserver < ActiveRecord::Observer
20
- $loaded_stuff << 'UserObserver'
21
- end
22
- """
23
- Given 'a file named "app/helpers/application_helper.rb" with:',
24
- """
25
- module ApplicationHelper
26
- $loaded_stuff << 'ApplicationHelper'
27
- end
28
- """
29
- Given 'the following code appears in "config/environment.rb" after /Rails::Initializer.run/:',
30
- """
31
- config.active_record.observers = :user_observer
32
- """
33
- Given 'the following code appears in "config/routes.rb" after /^end/:',
34
- """
35
- $loaded_stuff << 'config/routes.rb'
36
- """
37
- Given 'a file named "config/initializers/initialize_loaded_stuff.rb" with:',
38
- """
39
- $loaded_stuff ||= []
40
- """
41
- Given 'a file named "config/initializers/log_establish_connection_calls.rb" with:',
42
- """
43
- class ActiveRecord::Base
44
- class << self
45
- def establish_connection_with_load_logging(*args)
46
- establish_connection_without_load_logging(*args)
47
- $loaded_stuff << 'ActiveRecord::Base.establish_connection'
48
- end
49
- alias_method_chain :establish_connection, :load_logging
50
- end
51
- end
52
- """
1
+ Given /^I am in a fresh rails project named "(.+)"$/ do |folder_name|
2
+ @current_dir = SporkWorld::SANDBOX_DIR
3
+ version_argument = ENV['RAILS_VERSION'] ? "_#{ENV['RAILS_VERSION']}_" : nil
4
+ # run("#{SporkWorld::RUBY_BINARY} #{%x{which rails}.chomp} #{folder_name}")
5
+ run([SporkWorld::RUBY_BINARY, '-I', Cucumber::LIBDIR, %x{which rails}.chomp, version_argument, folder_name].compact * " ")
6
+ @current_dir = File.join(File.join(SporkWorld::SANDBOX_DIR, folder_name))
7
+ end
8
+
9
+
10
+ Given "the application has a model, observer, route, and application helper" do
11
+ Given 'a file named "app/models/user.rb" with:',
12
+ """
13
+ class User < ActiveRecord::Base
14
+ $loaded_stuff << 'User'
15
+ end
16
+ """
17
+ Given 'a file named "app/models/user_observer.rb" with:',
18
+ """
19
+ class UserObserver < ActiveRecord::Observer
20
+ $loaded_stuff << 'UserObserver'
21
+ end
22
+ """
23
+ Given 'a file named "app/helpers/application_helper.rb" with:',
24
+ """
25
+ module ApplicationHelper
26
+ $loaded_stuff << 'ApplicationHelper'
27
+ end
28
+ """
29
+ Given 'the following code appears in "config/environment.rb" after /Rails::Initializer.run/:',
30
+ """
31
+ config.active_record.observers = :user_observer
32
+ """
33
+ Given 'the following code appears in "config/routes.rb" after /^end/:',
34
+ """
35
+ $loaded_stuff << 'config/routes.rb'
36
+ """
37
+ Given 'a file named "config/initializers/initialize_loaded_stuff.rb" with:',
38
+ """
39
+ $loaded_stuff ||= []
40
+ """
41
+ Given 'a file named "config/initializers/log_establish_connection_calls.rb" with:',
42
+ """
43
+ class ActiveRecord::Base
44
+ class << self
45
+ def establish_connection_with_load_logging(*args)
46
+ establish_connection_without_load_logging(*args)
47
+ $loaded_stuff << 'ActiveRecord::Base.establish_connection'
48
+ end
49
+ alias_method_chain :establish_connection, :load_logging
50
+ end
51
+ end
52
+ """
53
53
  end
@@ -1,115 +1,115 @@
1
- Given /^I am in the directory "(.*)"$/ do |sandbox_dir_relative_path|
2
- path = File.join(SporkWorld::SANDBOX_DIR, sandbox_dir_relative_path)
3
- FileUtils.mkdir_p(path)
4
- @current_dir = File.join(path)
5
- end
6
-
7
- Given /^a file named "([^\"]*)"$/ do |file_name|
8
- create_file(file_name, '')
9
- end
10
-
11
- Given /^a file named "([^\"]*)" with:$/ do |file_name, file_content|
12
- create_file(file_name, file_content)
13
- end
14
-
15
- When /^the contents of "([^\"]*)" are changed to:$/ do |file_name, file_content|
16
- create_file(file_name, file_content)
17
- end
18
-
19
- # the following code appears in "config/environment.rb" after /Rails::Initializer.run/:
20
- Given /^the following code appears in "([^\"]*)" after \/([^\\\/]*)\/:$/ do |file_name, regex, content|
21
- regex = Regexp.new(regex)
22
- in_current_dir do
23
- content_lines = File.read(file_name).split("\n")
24
- 0.upto(content_lines.length - 1) do |line_index|
25
- if regex.match(content_lines[line_index])
26
- content_lines.insert(line_index + 1, content)
27
- break
28
- end
29
- end
30
- File.open(file_name, 'wb') { |f| f << (content_lines * "\n") }
31
- end
32
- end
33
-
34
- When /^I run (spork|spec|cucumber)(| .*)$/ do |command, args|
35
- run(localized_command(command, args))
36
- end
37
-
38
- When /^I run this in the background: (spork|spec|cucumber)(| .*)$/ do |command, args|
39
- @background_script = run_in_background(localized_command(command, args))
40
- end
41
-
42
- When /^I fire up a spork instance with "spork(.*)"$/ do |spork_opts|
43
- @spork_server = run_in_background("#{SporkWorld::RUBY_BINARY} -I #{Cucumber::LIBDIR} #{SporkWorld::BINARY} #{spork_opts}")
44
-
45
- output = ""
46
- begin
47
- status = Timeout::timeout(15) do
48
- # Something that should be interrupted if it takes too much time...
49
- while line = @spork_server.stderr.gets
50
- output << line
51
- puts line
52
- break if line.include?("Spork is ready and listening")
53
- end
54
- end
55
- rescue Timeout::Error
56
- puts "I can't seem to launch Spork properly. Output was:\n#{output}"
57
- true.should == false
58
- end
59
- end
60
-
61
- Then /^the spork window should output a line containing "(.+)"/ do |expected|
62
- output = ""
63
- begin
64
- status = Timeout::timeout(5) do
65
- # Something that should be interrupted if it takes too much time...
66
- while line = @spork_server.stdout.gets
67
- output << line
68
- puts line
69
- break if output.include?(expected)
70
- end
71
- end
72
- rescue Timeout::Error
73
- output.should include(expected)
74
- end
75
- end
76
-
77
- When /^I type this in the spork window: "(.+)"/ do |line|
78
- @spork_server.stdin.puts(line)
79
- @spork_server.stdin.flush
80
- end
81
-
82
-
83
- Then /^the file "([^\"]*)" should include "([^\"]*)"$/ do |filename, content|
84
- in_current_dir do
85
- File.read(filename).should include(content)
86
- end
87
- end
88
-
89
- Then /^the (error output|output) should contain$/ do |which, text|
90
- (which == "error output" ? last_stderr : last_stdout).should include(text)
91
- end
92
-
93
- Then /^the (error output|output) should contain "(.+)"$/ do |which, text|
94
- (which == "error output" ? last_stderr : last_stdout).should include(text)
95
- end
96
-
97
- Then /^the (error output|output) should match \/(.+)\/$/ do |which, regex|
98
- (which == "error output" ? last_stderr : last_stdout).should match(Regexp.new(regex))
99
- end
100
-
101
- Then /^the (error output|output) should not contain$/ do |which, text|
102
- (which == "error output" ? last_stderr : last_stdout).should_not include(text)
103
- end
104
-
105
- Then /^the (error output|output) should not contain "(.+)"$/ do |which, text|
106
- (which == "error output" ? last_stderr : last_stdout).should_not include(text)
107
- end
108
-
109
- Then /^the (error output|output) should be empty$/ do |which|
110
- (which == "error output" ? last_stderr : last_stdout).should == ""
111
- end
112
-
113
- Then /^the (error output|output) should be$/ do |which, text|
114
- (which == "error output" ? last_stderr : last_stdout).should == text
115
- end
1
+ Given /^I am in the directory "(.*)"$/ do |sandbox_dir_relative_path|
2
+ path = File.join(SporkWorld::SANDBOX_DIR, sandbox_dir_relative_path)
3
+ FileUtils.mkdir_p(path)
4
+ @current_dir = File.join(path)
5
+ end
6
+
7
+ Given /^a file named "([^\"]*)"$/ do |file_name|
8
+ create_file(file_name, '')
9
+ end
10
+
11
+ Given /^a file named "([^\"]*)" with:$/ do |file_name, file_content|
12
+ create_file(file_name, file_content)
13
+ end
14
+
15
+ When /^the contents of "([^\"]*)" are changed to:$/ do |file_name, file_content|
16
+ create_file(file_name, file_content)
17
+ end
18
+
19
+ # the following code appears in "config/environment.rb" after /Rails::Initializer.run/:
20
+ Given /^the following code appears in "([^\"]*)" after \/([^\\\/]*)\/:$/ do |file_name, regex, content|
21
+ regex = Regexp.new(regex)
22
+ in_current_dir do
23
+ content_lines = File.read(file_name).split("\n")
24
+ 0.upto(content_lines.length - 1) do |line_index|
25
+ if regex.match(content_lines[line_index])
26
+ content_lines.insert(line_index + 1, content)
27
+ break
28
+ end
29
+ end
30
+ File.open(file_name, 'wb') { |f| f << (content_lines * "\n") }
31
+ end
32
+ end
33
+
34
+ When /^I run (spork|spec|cucumber)(| .*)$/ do |command, args|
35
+ run(localized_command(command, args))
36
+ end
37
+
38
+ When /^I run this in the background: (spork|spec|cucumber)(| .*)$/ do |command, args|
39
+ @background_script = run_in_background(localized_command(command, args))
40
+ end
41
+
42
+ When /^I fire up a spork instance with "spork(.*)"$/ do |spork_opts|
43
+ @spork_server = run_in_background("#{SporkWorld::RUBY_BINARY} -I #{Cucumber::LIBDIR} #{SporkWorld::BINARY} #{spork_opts}")
44
+
45
+ output = ""
46
+ begin
47
+ status = Timeout::timeout(15) do
48
+ # Something that should be interrupted if it takes too much time...
49
+ while line = @spork_server.stderr.gets
50
+ output << line
51
+ puts line
52
+ break if line.include?("Spork is ready and listening")
53
+ end
54
+ end
55
+ rescue Timeout::Error
56
+ puts "I can't seem to launch Spork properly. Output was:\n#{output}"
57
+ true.should == false
58
+ end
59
+ end
60
+
61
+ Then /^the spork window should output a line containing "(.+)"/ do |expected|
62
+ output = ""
63
+ begin
64
+ status = Timeout::timeout(5) do
65
+ # Something that should be interrupted if it takes too much time...
66
+ while line = @spork_server.stdout.gets
67
+ output << line
68
+ puts line
69
+ break if output.include?(expected)
70
+ end
71
+ end
72
+ rescue Timeout::Error
73
+ output.should include(expected)
74
+ end
75
+ end
76
+
77
+ When /^I type this in the spork window: "(.+)"/ do |line|
78
+ @spork_server.stdin.puts(line)
79
+ @spork_server.stdin.flush
80
+ end
81
+
82
+
83
+ Then /^the file "([^\"]*)" should include "([^\"]*)"$/ do |filename, content|
84
+ in_current_dir do
85
+ File.read(filename).should include(content)
86
+ end
87
+ end
88
+
89
+ Then /^the (error output|output) should contain$/ do |which, text|
90
+ (which == "error output" ? last_stderr : last_stdout).should include(text)
91
+ end
92
+
93
+ Then /^the (error output|output) should contain "(.+)"$/ do |which, text|
94
+ (which == "error output" ? last_stderr : last_stdout).should include(text)
95
+ end
96
+
97
+ Then /^the (error output|output) should match \/(.+)\/$/ do |which, regex|
98
+ (which == "error output" ? last_stderr : last_stdout).should match(Regexp.new(regex))
99
+ end
100
+
101
+ Then /^the (error output|output) should not contain$/ do |which, text|
102
+ (which == "error output" ? last_stderr : last_stdout).should_not include(text)
103
+ end
104
+
105
+ Then /^the (error output|output) should not contain "(.+)"$/ do |which, text|
106
+ (which == "error output" ? last_stderr : last_stdout).should_not include(text)
107
+ end
108
+
109
+ Then /^the (error output|output) should be empty$/ do |which|
110
+ (which == "error output" ? last_stderr : last_stdout).should == ""
111
+ end
112
+
113
+ Then /^the (error output|output) should be$/ do |which, text|
114
+ (which == "error output" ? last_stderr : last_stdout).should == text
115
+ end
@@ -1,63 +1,63 @@
1
- class BackgroundJob
2
- attr_reader :stdin, :stdout, :stderr, :pid
3
- def initialize(pid, stdin, stdout, stderr)
4
- @pid, @stdin, @stdout, @stderr = pid, stdin, stdout, stderr
5
- ObjectSpace.define_finalizer(self) { kill }
6
- end
7
-
8
- def self.run(command)
9
- command = sanitize_params(command) if command.is_a?(Array)
10
- child_stdin, parent_stdin = IO::pipe
11
- parent_stdout, child_stdout = IO::pipe
12
- parent_stderr, child_stderr = IO::pipe
13
-
14
- pid = Kernel.fork do
15
- [parent_stdin, parent_stdout, parent_stderr].each { |io| io.close }
16
-
17
- STDIN.reopen(child_stdin)
18
- STDOUT.reopen(child_stdout)
19
- STDERR.reopen(child_stderr)
20
-
21
- [child_stdin, child_stdout, child_stderr].each { |io| io.close }
22
-
23
- exec command
24
- end
25
-
26
- [child_stdin, child_stdout, child_stderr].each { |io| io.close }
27
- parent_stdin.sync = true
28
-
29
- new(pid, parent_stdin, parent_stdout, parent_stderr)
30
- end
31
-
32
- def self.sanitize_params(params)
33
- params.map { |p| p.gsub(' ', '\ ') }.join(" ")
34
- end
35
-
36
- def kill(signal = 'TERM')
37
- if running?
38
- Process.kill(Signal.list[signal], @pid)
39
- true
40
- end
41
- end
42
-
43
- def interrupt
44
- kill('INT')
45
- end
46
-
47
- def running?
48
- return false unless @pid
49
- Process.getpgid(@pid)
50
- true
51
- rescue Errno::ESRCH
52
- false
53
- end
54
-
55
- def wait(timeout = 1000)
56
- Timeout.timeout(timeout) do
57
- Process.wait(@pid)
58
- end
59
- true
60
- rescue Timeout::Error
61
- false
62
- end
63
- end
1
+ class BackgroundJob
2
+ attr_reader :stdin, :stdout, :stderr, :pid
3
+ def initialize(pid, stdin, stdout, stderr)
4
+ @pid, @stdin, @stdout, @stderr = pid, stdin, stdout, stderr
5
+ ObjectSpace.define_finalizer(self) { kill }
6
+ end
7
+
8
+ def self.run(command)
9
+ command = sanitize_params(command) if command.is_a?(Array)
10
+ child_stdin, parent_stdin = IO::pipe
11
+ parent_stdout, child_stdout = IO::pipe
12
+ parent_stderr, child_stderr = IO::pipe
13
+
14
+ pid = Kernel.fork do
15
+ [parent_stdin, parent_stdout, parent_stderr].each { |io| io.close }
16
+
17
+ STDIN.reopen(child_stdin)
18
+ STDOUT.reopen(child_stdout)
19
+ STDERR.reopen(child_stderr)
20
+
21
+ [child_stdin, child_stdout, child_stderr].each { |io| io.close }
22
+
23
+ exec command
24
+ end
25
+
26
+ [child_stdin, child_stdout, child_stderr].each { |io| io.close }
27
+ parent_stdin.sync = true
28
+
29
+ new(pid, parent_stdin, parent_stdout, parent_stderr)
30
+ end
31
+
32
+ def self.sanitize_params(params)
33
+ params.map { |p| p.gsub(' ', '\ ') }.join(" ")
34
+ end
35
+
36
+ def kill(signal = 'TERM')
37
+ if running?
38
+ Process.kill(Signal.list[signal], @pid)
39
+ true
40
+ end
41
+ end
42
+
43
+ def interrupt
44
+ kill('INT')
45
+ end
46
+
47
+ def running?
48
+ return false unless @pid
49
+ Process.getpgid(@pid)
50
+ true
51
+ rescue Errno::ESRCH
52
+ false
53
+ end
54
+
55
+ def wait(timeout = 1000)
56
+ Timeout.timeout(timeout) do
57
+ Process.wait(@pid)
58
+ end
59
+ true
60
+ rescue Timeout::Error
61
+ false
62
+ end
63
+ end