spin 0.2.0 → 0.2.1

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.
Files changed (2) hide show
  1. data/bin/spin +21 -8
  2. metadata +4 -4
data/bin/spin CHANGED
@@ -47,15 +47,19 @@ end
47
47
  # ## spin serve
48
48
  def serve(force_rspec, force_testunit, time, push_results)
49
49
  file = socket_file
50
+
50
51
  # We delete the tmp file for the Unix socket if it already exists. The file
51
52
  # is scoped to the `pwd`, so if it already exists then it must be from an
52
53
  # old run of `spin serve` and can be cleaned up.
53
54
  File.delete(file) if File.exist?(file)
55
+
54
56
  # This socket is how we communicate with `spin push`.
55
57
  socket = UNIXServer.open(file)
56
58
 
57
59
  ENV['RAILS_ENV'] = 'test' unless ENV['RAILS_ENV']
58
60
 
61
+ test_framework = nil
62
+
59
63
  if File.exist? 'config/application.rb'
60
64
  sec = Benchmark.realtime {
61
65
  # We require config/application because that file (typically) loads Rails
@@ -69,6 +73,19 @@ def serve(force_rspec, force_testunit, time, push_results)
69
73
  # involve it's models/controllers, etc. in its initialization, which you
70
74
  # definitely don't want to preload.
71
75
  require File.expand_path 'config/application'
76
+
77
+ # Determine the test framework to use using the passed-in 'force' options
78
+ # or else default to checking for defined constants.
79
+ test_framework = determine_test_framework(force_rspec, force_testunit)
80
+
81
+ # Preload RSpec to save some time on each test run
82
+ ['rspec', 'rspec/rails', 'rspec/autorun'].each do |gem|
83
+ begin
84
+ require gem
85
+ rescue LoadError
86
+ # do nothing
87
+ end
88
+ end if test_framework == :rspec
72
89
  }
73
90
  # This is the amount of time that you'll save on each subsequent test run.
74
91
  puts "Preloaded Rails env in #{sec}s..."
@@ -89,7 +106,7 @@ def serve(force_rspec, force_testunit, time, push_results)
89
106
  # If spin is started with the time flag we will track total execution so
90
107
  # you can easily compare it with time rspec spec for example
91
108
  start = Time.now if time
92
-
109
+
93
110
  # If we're not sending results back to the push process, we can disconnect
94
111
  # it immediately.
95
112
  disconnect(conn) unless push_results
@@ -99,7 +116,7 @@ def serve(force_rspec, force_testunit, time, push_results)
99
116
  # needs to, then it exits and we're back to the baseline preloaded app.
100
117
  fork do
101
118
  # To push the test results to the push process instead of having them
102
- # displayed by the server, we reopen $stdout/$stderr to the open
119
+ # displayed by the server, we reopen $stdout/$stderr to the open
103
120
  # connection.
104
121
  if push_results
105
122
  $stdout.reopen(conn)
@@ -109,10 +126,6 @@ def serve(force_rspec, force_testunit, time, push_results)
109
126
  puts
110
127
  puts "Loading #{files.inspect}"
111
128
 
112
- # Determine the test framework to use using the passed-in 'force' options
113
- # or else default to checking for defined constants.
114
- test_framework = determine_test_framework(force_rspec, force_testunit)
115
-
116
129
  # Unfortunately rspec's interface isn't as simple as just requiring the
117
130
  # test file that you want to run (suddenly test/unit seems like the less
118
131
  # crazy one!).
@@ -120,7 +133,6 @@ def serve(force_rspec, force_testunit, time, push_results)
120
133
  # We pretend the filepath came in as an argument and duplicate the
121
134
  # behaviour of the `rspec` binary.
122
135
  ARGV.push files
123
- require 'rspec/autorun'
124
136
  else
125
137
  # We require the full path of the file here in the child process.
126
138
  files.each { |f| require File.expand_path f }
@@ -136,7 +148,7 @@ def serve(force_rspec, force_testunit, time, push_results)
136
148
  # If we are tracking time we will output it here after everything has
137
149
  # finished running
138
150
  puts "Total execution time was #{Time.now - start} seconds" if start
139
-
151
+
140
152
  # Tests have now run. If we were pushing results to a push process, we can
141
153
  # now disconnect it.
142
154
  begin
@@ -222,3 +234,4 @@ else
222
234
  $stderr.puts options
223
235
  exit 1
224
236
  end
237
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spin
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jesse Storimer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-19 00:00:00 -05:00
18
+ date: 2011-11-27 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies: []
21
21