Skip to content

Commit

Permalink
Updated Ruby versions/platform against guard-spork is tested + cleane…
Browse files Browse the repository at this point in the history
…d up some docs.

Signed-off-by: Rémy Coutable <rymai@rymai.me>
  • Loading branch information
Rémy Coutable committed Apr 17, 2011
1 parent 4af9541 commit 234894f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 30 deletions.
30 changes: 14 additions & 16 deletions README.rdoc
Expand Up @@ -2,8 +2,8 @@

Guard::Spork allows to automatically & intelligently start/reload your RSpec/Cucumber {Spork}[https://github.com/timcharper/spork] server(s).

- Compatible with Spork 0.8.4 & 0.9.0.rc3.
- Tested on Ruby 1.8.6, 1.8.7 & 1.9.2.
- Compatible with Spork 0.8.4 & 0.9.0.rcXX.
- Tested on Ruby 1.8.6, 1.8.7, REE, 1.9.2, JRuby & Rubinius.

== Install

Expand Down Expand Up @@ -61,30 +61,28 @@ Guard::Spork automatically detect RSpec/Cucumber/Bundler presence but you can di
...
end

To append additional environment variables for rspec and cucumber you can provided a hash to rspec_env/cucumber_env:
You can provide additional environment variables for RSpec and Cucumber with the <tt>:rspec_env</tt> and <tt>:cucumber_env</tt> options:

guard 'spork', :cucumber_env => {'RAILS_ENV' => 'cucumber'}, :rspec_env => {'RAILS_ENV' => 'test'} do
guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'cucumber' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
...
end

<b>IMPORTANT: when using ruby 1.8.x please set the env for both rspec and cucumber as they will overwrite each other and the system env's</b>


Available options:

:wait => 30 # Seconds to wait for the server to starts, default: 20
:cucumber => false
:rspec => false
:bundler => false # Don't use "bundle exec"
:rspec_port => 1234 # Default: 8989
:cucumber_port => 4321 # Default: 8990
:rspec_env
:cucumber_env
:wait => 30 # Seconds to wait for the server to starts, default: 20
:cucumber => false
:rspec => false
:bundler => false # Don't use "bundle exec"
:rspec_port => 1234 # Default: 8989
:cucumber_port => 4321 # Default: 8990
:rspec_env => { 'RAILS_ENV' => 'foo' } # Default: nil
:cucumber_env => { 'RAILS_ENV' => 'bar' } # Default: nil

== Common troubleshooting

If you can start Spork manually but get the following error message when using Guard::Spork:

Starting Spork for RSpec ERROR: Could not start Spork for RSpec/Cucumber. Make sure you can use it manually first.
Starting Spork for RSpec ERROR: Could not start Spork for RSpec/Cucumber. Make sure you can use it manually first.

Try to increase the value of the <tt>:wait</tt> option before any further investigation.

Expand Down
25 changes: 17 additions & 8 deletions lib/guard/spork/runner.rb
Expand Up @@ -37,15 +37,10 @@ def spawn_child(env, cmd)

unless pid
ignore_control_signals
if env
if RUBY_VERSION > "1.9"
exec(env, cmd)
else
env.each { |key, value| ENV[key] = value }
exec(cmd)
end
if RUBY_VERSION > "1.9"
exec(env, cmd)
else
exec(cmd)
swap_env(env || []) { exec(cmd) }
end
end

Expand All @@ -60,6 +55,20 @@ def ignore_control_signals
Signal.trap('TSTP', 'IGNORE')
end

def swap_env(env)
old_env = {}
env.each do |key, value|
old_env[key] = ENV[key]
ENV[key] = value
end

yield

env.each do |key, value|
ENV[key] = old_env[key]
end
end

def reap_children(sig)
terminated_children.each do |stat|
pid = stat.pid
Expand Down
28 changes: 22 additions & 6 deletions spec/guard/spork/runner_spec.rb
Expand Up @@ -4,11 +4,11 @@
subject { Guard::Spork::Runner.new }

describe "#initialize" do
it "default options are { :cucumber_port => 8990, :rspec_port => 8989, :wait => 20, :rspec_env => nil, :cucumber_env => nil }" do
it "default options are { :wait => 20, :cucumber_port => 8990, :rspec_port => 8989, :rspec_env => nil, :cucumber_env => nil }" do
subject.options.should == {
:wait => 20,
:cucumber_port => 8990,
:rspec_port => 8989,
:wait => 20,
:rspec_env => nil,
:cucumber_env => nil
}
Expand All @@ -17,7 +17,6 @@

describe "#launch_sporks" do
before(:each) do
subject.stub(:spawn_child) { true }
Dir.stub(:pwd) { "" }
end

Expand Down Expand Up @@ -83,9 +82,14 @@

describe ":rspec_env & :cucumber_env options" do
before(:each) do
subject.options = {:cucumber_port => 8990, :rspec_port => 8989, :wait => 1, :cucumber_env => {'RAILS_ENV' => 'cucumber'}, :rspec_env => {'RAILS_ENV' => 'test'}}
subject.stub(:spawn_child) { true }
Dir.stub(:pwd) { "" }
subject.options = {
:wait => 20,
:cucumber_port => 8990,
:rspec_port => 8989,
:rspec_env => { 'RAILS_ENV' => 'test' },
:cucumber_env => { 'RAILS_ENV' => 'cucumber' }
}
Dir.stub(:pwd) { "" }
end

context "with RSpec only" do
Expand Down Expand Up @@ -151,6 +155,18 @@
end
end

describe "#swap_env" do
before(:each) do
ENV['FOO_ENV'] = 'foo'
end

it "doesn't change current ENV" do
ENV['FOO_ENV'].should == 'foo'
subject.send(:swap_env, { 'FOO_ENV' => 'test' }) { "Foo" }
ENV['FOO_ENV'].should == 'foo'
end
end

describe "#kill_sporks" do
it "calls a KILL command for each Spork server" do
subject.should_receive(:spork_pids).twice.and_return([666, 999])
Expand Down

0 comments on commit 234894f

Please sign in to comment.