spork 0.4.4 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ Spork::AppFramework[:Rails]
4
+
5
+ describe Spork::AppFramework::Rails do
6
+ describe ".version" do
7
+ it "detects the current version of rails" do
8
+ create_file("config/environment.rb", "RAILS_GEM_VERSION = '2.1.0'")
9
+ in_current_dir do
10
+ Spork::AppFramework::Rails.new.version.should == "2.1.0"
11
+ end
12
+
13
+ create_file("config/environment.rb", 'RAILS_GEM_VERSION = "2.1.0"')
14
+ in_current_dir do
15
+ Spork::AppFramework::Rails.new.version.should == "2.1.0"
16
+ end
17
+
18
+ create_file("config/environment.rb", 'RAILS_GEM_VERSION = "> 2.1.0"')
19
+ in_current_dir do
20
+ Spork::AppFramework::Rails.new.version.should == "> 2.1.0"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Spork::AppFramework do
4
+ describe ".detect_framework" do
5
+ it "detects when rails is installed and available" do
6
+ create_file("config/environment.rb", "RAILS_GEM_VERSION = '2.1.0'")
7
+ in_current_dir do
8
+ Spork::AppFramework.detect_framework.name.should == "Rails"
9
+ end
10
+ end
11
+
12
+ it "returns Unknown when no framework known detected" do
13
+ Spork::AppFramework.detect_framework.name.should == "Unknown"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,91 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+
4
+ describe Spork::Diagnoser do
5
+ after(:each) do
6
+ Spork::Diagnoser.remove_hook!
7
+ Spork::Diagnoser.loaded_files.clear
8
+ end
9
+
10
+ def run_simulation(directory, filename = nil, contents = nil, &block)
11
+ FileUtils.mkdir_p(directory)
12
+ Dir.chdir(directory) do
13
+ if filename
14
+ File.open(filename, 'wb') { |f| f << contents }
15
+ Spork::Diagnoser.install_hook!
16
+ require filename
17
+ end
18
+ yield if block_given?
19
+ end
20
+ end
21
+
22
+ it "installs it's hook and tells you when files have been loaded" do
23
+ run_simulation(SPEC_TMP_DIR, 'my_awesome_library_include.rb', '1 + 5')
24
+ Spork::Diagnoser.loaded_files.keys.should include_a_string_like('my_awesome_library_include')
25
+
26
+ end
27
+
28
+ it 'excludes files outside of Dir.pwd' do
29
+ run_simulation(SPEC_TMP_DIR + '/project_root', '../external_dependency.rb', '1 + 5')
30
+ Spork::Diagnoser.loaded_files.keys.should_not include_a_string_like('external_dependency')
31
+
32
+ end
33
+
34
+ it "excludes files outside of Dir.pwd but in ruby's include path" do
35
+ directory = SPEC_TMP_DIR + '/project_root'
36
+ external_dependency_dir = SPEC_TMP_DIR + '/external_dependency'
37
+ $: << external_dependency_dir
38
+ FileUtils.mkdir_p(directory)
39
+ FileUtils.mkdir_p(external_dependency_dir)
40
+ Dir.chdir(directory) do
41
+ File.open(external_dependency_dir + '/the_most_awesome_external_dependency_ever.rb', 'wb') { |f| f << 'funtimes = true' }
42
+ Spork::Diagnoser.install_hook!
43
+ require 'the_most_awesome_external_dependency_ever'
44
+ end
45
+
46
+ Spork::Diagnoser.loaded_files.keys.should_not include_a_string_like('the_most_awesome_external_dependency_ever')
47
+ $:.pop
48
+ end
49
+
50
+ it "expands files to their fully their fully qualified path" do
51
+ directory = SPEC_TMP_DIR + '/project_root'
52
+ lib_directory = directory + '/lib'
53
+ $: << lib_directory
54
+ FileUtils.mkdir_p(lib_directory)
55
+ Dir.chdir(directory) do
56
+ File.open(lib_directory + "/the_most_awesome_lib_file_ever.rb", "wb") { |f| f << "funtimes = true" }
57
+ Spork::Diagnoser.install_hook!
58
+ require 'the_most_awesome_lib_file_ever'
59
+ end
60
+
61
+ Spork::Diagnoser.loaded_files.keys.should include_a_string_like('lib/the_most_awesome_lib_file_ever')
62
+ $:.pop
63
+ end
64
+
65
+ it "can tell the difference between a folder in the project path and a file in an external path" do
66
+ directory = SPEC_TMP_DIR + '/project_root'
67
+ external_dependency_dir = SPEC_TMP_DIR + '/external_dependency'
68
+ $: << external_dependency_dir
69
+ FileUtils.mkdir_p(directory)
70
+ FileUtils.mkdir_p(external_dependency_dir)
71
+ Dir.chdir(directory) do
72
+ FileUtils.mkdir_p(directory + '/a_popular_folder_name')
73
+ File.open(external_dependency_dir + '/a_popular_folder_name.rb', 'wb') { |f| f << 'funtimes = true' }
74
+ Spork::Diagnoser.install_hook!
75
+ require 'a_popular_folder_name'
76
+ end
77
+
78
+ Spork::Diagnoser.loaded_files.keys.should_not include_a_string_like('a_popular_folder_name')
79
+ $:.pop
80
+ end
81
+
82
+ it "outputs the results relative to the current directory" do
83
+ Spork::Diagnoser.loaded_files["/project_path/lib/file.rb"] = "/project_path/lib/parent_file.rb:35"
84
+ Dir.stub!(:pwd).and_return("/project_path")
85
+ out = StringIO.new
86
+ Spork::Diagnoser.output_results(out)
87
+ out.string.should =~ %r([^/]lib/file.rb)
88
+ out.string.should =~ %r([^/]lib/parent_file.rb)
89
+ out.string.should_not include("/project_path/")
90
+ end
91
+ end
@@ -11,7 +11,7 @@ describe Spork::Runner do
11
11
 
12
12
  it "shows an error message if no matching server was found" do
13
13
  Spork::Runner.new(["argle_bargle"], @out, @err).run.should == false
14
- @out.string.should include(%("argle_bargle" didn't match a supported test framework))
14
+ @err.string.should include(%("argle_bargle" didn't match a supported test framework))
15
15
  end
16
16
 
17
17
  it "defaults to use rspec over cucumber" do
@@ -44,7 +44,7 @@ describe Spork::Runner do
44
44
  Spork::Server::RSpec.should_receive(:preload).and_return(true)
45
45
  Spork::Server::RSpec.should_receive(:run).and_return(true)
46
46
  Spork::Runner.new(['rspec'], @out, @err).run
47
- @out.string.should include("Using RSpec")
47
+ @err.string.should include("Using RSpec")
48
48
  end
49
49
 
50
50
  it "outputs a list of supported servers, along with supported asterisk" do
@@ -1,7 +1,11 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
+
3
4
  class FakeServer < Spork::Server
4
5
  attr_accessor :wait_time
6
+
7
+ include Spork::TestIOStreams
8
+
5
9
  def self.helper_file
6
10
  SPEC_TMP_DIR + "/fake/test_helper.rb"
7
11
  end
@@ -10,14 +14,6 @@ class FakeServer < Spork::Server
10
14
  1000
11
15
  end
12
16
 
13
- def self.puts(string)
14
- $test_stdout.puts(string)
15
- end
16
-
17
- def puts(string)
18
- $test_stdout.puts(string)
19
- end
20
-
21
17
  def run_tests(argv, input, output)
22
18
  sleep(@wait_time || 0.5)
23
19
  true
@@ -58,8 +54,7 @@ describe Spork::Server do
58
54
 
59
55
  describe "a fake server" do
60
56
  def create_helper_file
61
- FileUtils.mkdir_p(File.dirname(FakeServer.helper_file))
62
- FileUtils.touch(FakeServer.helper_file)
57
+ create_file(FakeServer.helper_file, "# stub spec helper file")
63
58
  end
64
59
 
65
60
  before(:each) do
@@ -94,9 +89,9 @@ describe Spork::Server do
94
89
  create_helper_file
95
90
  FakeServer.bootstrap
96
91
 
97
- $test_stdout.string.should include("Bootstrapping")
98
- $test_stdout.string.should include("Edit")
99
- $test_stdout.string.should include("favorite text editor")
92
+ $test_stderr.string.should include("Bootstrapping")
93
+ $test_stderr.string.should include("Edit")
94
+ $test_stderr.string.should include("favorite text editor")
100
95
 
101
96
  File.read(FakeServer.helper_file).should include(File.read(FakeServer::BOOTSTRAP_FILE))
102
97
  end
@@ -3,8 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  Spork.class_eval do
4
4
  def self.reset!
5
5
  @state = nil
6
- @already_run = nil
7
- @already_preforked = nil
6
+ @already_ran = nil
8
7
  end
9
8
  end
10
9
 
@@ -14,28 +13,28 @@ describe Spork do
14
13
  end
15
14
 
16
15
  def spec_helper_simulator
17
- ran = []
16
+ @ran ||= []
18
17
  Spork.prefork do
19
- ran << :prefork
18
+ @ran << :prefork
20
19
  end
21
20
 
22
21
  Spork.each_run do
23
- ran << :each_run
22
+ @ran << :each_run
24
23
  end
25
- ran
24
+ @ran
26
25
  end
27
26
 
28
27
  it "only runs the preload block when preforking" do
29
- ran = []
30
- Spork.preforking!
31
- spec_helper_simulator.should == [:prefork]
28
+ Spork.exec_prefork { spec_helper_simulator }
29
+ @ran.should == [:prefork]
32
30
  end
33
31
 
34
32
  it "only runs the each_run block when running" do
35
- Spork.preforking!
36
- spec_helper_simulator
37
- Spork.running!
38
- spec_helper_simulator.should == [:each_run]
33
+ Spork.exec_prefork { spec_helper_simulator }
34
+ @ran.should == [:prefork]
35
+
36
+ Spork.exec_each_run
37
+ @ran.should == [:prefork, :each_run]
39
38
  end
40
39
 
41
40
  it "runs both blocks when Spork not activated" do
@@ -43,8 +42,12 @@ describe Spork do
43
42
  end
44
43
 
45
44
  it "prevents blocks from being ran twice" do
46
- spec_helper_simulator.should == [:prefork, :each_run]
47
- spec_helper_simulator.should == []
45
+ Spork.exec_prefork { spec_helper_simulator }
46
+ Spork.exec_each_run
47
+ @ran.clear
48
+ Spork.exec_prefork { spec_helper_simulator }
49
+ Spork.exec_each_run
50
+ @ran.should == []
48
51
  end
49
52
 
50
53
  it "runs multiple prefork and each_run blocks at different locations" do
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.4.4
4
+ version: 0.5.1
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-06-01 00:00:00 -06:00
12
+ date: 2009-06-06 00:00:00 -06:00
13
13
  default_executable: spork
14
14
  dependencies: []
15
15
 
@@ -27,13 +27,29 @@ files:
27
27
  - MIT-LICENSE
28
28
  - README.rdoc
29
29
  - assets/bootstrap.rb
30
+ - features/diagnostic_mode.feature
31
+ - features/rails_integration.feature
32
+ - features/steps/rails_steps.rb
33
+ - features/steps/sandbox_steps.rb
34
+ - features/support/env.rb
30
35
  - lib/spork.rb
36
+ - lib/spork/app_framework.rb
37
+ - lib/spork/app_framework/rails.rb
38
+ - lib/spork/app_framework/rails_stub_files/application.rb
39
+ - lib/spork/app_framework/rails_stub_files/application_controller.rb
40
+ - lib/spork/app_framework/rails_stub_files/application_helper.rb
41
+ - lib/spork/app_framework/unknown.rb
42
+ - lib/spork/custom_io_streams.rb
43
+ - lib/spork/diagnoser.rb
31
44
  - lib/spork/forker.rb
32
45
  - lib/spork/runner.rb
33
46
  - lib/spork/server.rb
34
47
  - lib/spork/server/cucumber.rb
35
48
  - lib/spork/server/rspec.rb
36
49
  - spec/spec_helper.rb
50
+ - spec/spork/app_framework/rails_spec.rb
51
+ - spec/spork/app_framework_spec.rb
52
+ - spec/spork/diagnoser_spec.rb
37
53
  - spec/spork/forker_spec.rb
38
54
  - spec/spork/runner_spec.rb
39
55
  - spec/spork/server/rspec_spec.rb
@@ -68,6 +84,9 @@ specification_version: 2
68
84
  summary: spork
69
85
  test_files:
70
86
  - spec/spec_helper.rb
87
+ - spec/spork/app_framework/rails_spec.rb
88
+ - spec/spork/app_framework_spec.rb
89
+ - spec/spork/diagnoser_spec.rb
71
90
  - spec/spork/forker_spec.rb
72
91
  - spec/spork/runner_spec.rb
73
92
  - spec/spork/server/rspec_spec.rb