Skip to content

Commit

Permalink
Fix tests to make them run out of the box on different rubies
Browse files Browse the repository at this point in the history
  • Loading branch information
jonleighton committed Feb 15, 2013
1 parent f6b8b6b commit 1b719bd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
46 changes: 25 additions & 21 deletions test/acceptance/app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ def app_root
Pathname.new("#{TEST_ROOT}/apps/rails-3-2")
end

def gem_home
app_root.join "vendor/gems/#{RUBY_VERSION}"
end

def spring
gem_home.join "bin/spring"
end

def server_pidfile
"#{app_root}/tmp/spring/#{Spring::SID.sid}.pid"
end
Expand Down Expand Up @@ -38,12 +46,8 @@ def app_run(command, opts = {})

Bundler.with_clean_env do
Process.spawn(
{
"GEM_HOME" => "#{app_root}/vendor/gems",
"GEM_PATH" => "",
"PATH" => "#{app_root}/vendor/gems/bin:#{ENV["PATH"]}"
},
command,
{ "GEM_HOME" => gem_home.to_s, "GEM_PATH" => "" },
command.to_s,
out: stdout.last,
err: stderr.last,
chdir: app_root.to_s,
Expand Down Expand Up @@ -118,10 +122,10 @@ def assert_server_not_running(*args)
end

def test_command
"spring test #{@test}"
"#{spring} test #{@test}"
end

@@installed_spring = false
@@installed = false

setup do
@test = "#{app_root}/test/functional/posts_controller_test.rb"
Expand All @@ -131,17 +135,17 @@ def test_command

@spring_env = Spring::Env.new(app_root)

unless @@installed_spring
unless @@installed
FileUtils.mkdir_p(gem_home)
system "gem build spring.gemspec 2>/dev/null 1>/dev/null"
app_run "gem install ../../../spring-*.gem"
@@installed_spring = true
app_run "gem install ../../../spring-#{Spring::VERSION}.gem"
app_run "(gem list bundler | grep bundler) || gem install bundler #{'--pre' if RUBY_VERSION >= "2.0"}", timeout: nil
app_run "bundle check || bundle update", timeout: nil
app_run "bundle exec rake db:migrate"
@@installed = true
end

FileUtils.rm_rf "#{app_root}/bin"
app_run "(gem list bundler | grep bundler) || gem install bundler", timeout: nil
app_run "bundle check || bundle update", timeout: nil
app_run "bundle exec rake db:migrate"

@times = []
end

Expand All @@ -163,7 +167,7 @@ def test_command
end

test "help message when called without arguments" do
assert_stdout "spring", 'Usage: spring COMMAND [ARGS]'
assert_stdout spring, 'Usage: spring COMMAND [ARGS]'
end

test "test changes are picked up" do
Expand Down Expand Up @@ -252,28 +256,28 @@ def self.omg
assert_successful_run test_command
assert_server_running

assert_successful_run 'spring stop'
assert_successful_run "#{spring} stop"
assert_server_not_running
end

test "custom commands" do
assert_stdout "spring custom", "omg"
assert_stdout "#{spring} custom", "omg"
end

test "runner alias" do
assert_stdout "spring r 'puts 1'", "1"
assert_stdout "#{spring} r 'puts 1'", "1"
end

test "binstubs" do
app_run "spring binstub rake"
app_run "#{spring} binstub rake"
assert_successful_run "bin/spring help"
assert_stdout "bin/rake -T", "rake db:migrate"
end

test "missing config/application.rb" do
begin
FileUtils.mv app_root.join("config/application.rb"), app_root.join("config/application.rb.bak")
assert_stderr "spring rake -T", "unable to find your config/application.rb"
assert_stderr "#{spring} rake -T", "unable to find your config/application.rb"
ensure
FileUtils.mv app_root.join("config/application.rb.bak"), app_root.join("config/application.rb")
end
Expand Down
2 changes: 1 addition & 1 deletion test/apps/rails-3-2/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
/tmp

/bin
/vendor/gems/*
/vendor/gems
Empty file.

0 comments on commit 1b719bd

Please sign in to comment.