Skip to content

Commit aae522a

Browse files
committed
improve multi-ruby test framework
1 parent ef3a347 commit aae522a

File tree

9 files changed

+38
-29
lines changed

9 files changed

+38
-29
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ test/adapters/railsapp
88
.DS_Store
99
vendor/cache/
1010

11+
vendor/cache
12+
test/adapters/rspec1/vendor/cache
13+
test/adapters/rspec2/vendor/cache

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
source :rubygems
22

3-
gemspec name: "wrong"
3+
gemspec :name => "wrong"
44

55
group :development, :test do
66
gem "rvm"

Rakefile

+19-21
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ task :default => :test
66

77
def separate
88
Dir["./test/adapters/*_test.rb"] + [
9-
"./test/message/test_context_test.rb",
10-
"./test/assert_advanced_test.rb",
9+
"./test/message/test_context_test.rb",
10+
"./test/assert_advanced_test.rb",
1111
]
1212
end
1313

@@ -58,49 +58,54 @@ end
5858
# end
5959

6060
namespace :rvm do
61+
require 'rvm'
6162

6263
# todo: use https://gist.github.com/674648 technique instead
63-
# $: << ENV["HOME"] + "/.rvm/lib"
64+
# $: << ENV["HOME"] + "/.rvm/lib"
6465
require 'rvm'
6566

6667
@rubies=['1.8.6',
6768
'1.8.7',
68-
'1.9.1-p378', # we can't use p429 or p431, see http://bugs.ruby-lang.org/issues/show/3584
69+
'1.9.1-p378', # we can't use p429 or p431, see http://bugs.ruby-lang.org/issues/show/3584 and http://bugs.ruby-lang.org/issues/2404
6970
'1.9.2',
7071
'1.9.3',
7172
'jruby']
7273
@rubies_str = @rubies.join(', ')
7374

7475
def rvm
75-
rvm = `which rvm`.strip
76-
raise 'rvm not available; go to http://rvm.beginrescueend.com' unless rvm
77-
rvm
76+
@rvm_path ||= begin
77+
rvm = `which rvm`.strip
78+
raise 'rvm not available; go to http://rvm.beginrescueend.com' unless rvm
79+
rvm
80+
end
7881
end
7982

8083
def rvm_run(cmd, options = {})
8184
options = {:bundle_check => true}.merge(options)
8285
@rubies.each do |version|
86+
87+
available_versions = RVM.list_strings
88+
version = available_versions.grep(/#{version}/).last
89+
8390
puts "\n== Using #{version}"
8491
using = `#{rvm} #{version} exec true`
8592
if using =~ /not installed/
8693
puts "== #{using}"
8794
else
8895
if options[:bundle_check]
8996
Bundler.with_clean_env do
90-
sys "#{rvm} #{version} exec bundle check"
97+
prefix = "#{rvm} #{version} exec"
98+
sys "#{prefix} bundle check"
9199
if $?.exitstatus != 0
92-
puts "try rake rvm:install_bundler or rake rvm:install_gems"
100+
sys("#{prefix} bundle install")
101+
sys("#{prefix} bundle install --gemfile=#{File.dirname __FILE__}/test/adapters/rspec1/Gemfile")
102+
sys("#{prefix} bundle install --gemfile=#{File.dirname __FILE__}/test/adapters/rspec2/Gemfile")
93103
end
94104
end
95105
end
96106

97107
Bundler.with_clean_env do
98108
sys "#{rvm} #{version} exec #{cmd}"
99-
if $?.exitstatus == 7
100-
puts "try rake rvm:install_gems"
101-
elsif $?.exitstatus == 1
102-
# uh...
103-
end
104109
end
105110
end
106111
end
@@ -120,13 +125,6 @@ namespace :rvm do
120125
task :install_bundler do
121126
rvm_run("gem install bundler", :bundle_check => false)
122127
end
123-
124-
desc "run 'bundle install' with rvm in each of #{@rubies_str}"
125-
task :install_gems do
126-
rvm_run("bundle install", :bundle_check => false)
127-
rvm_run("bundle install --gemfile=#{File.dirname __FILE__}/test/adapters/rspec1/Gemfile", :bundle_check => false)
128-
rvm_run("bundle install --gemfile=#{File.dirname __FILE__}/test/adapters/rspec2/Gemfile", :bundle_check => false)
129-
end
130128
end
131129

132130
def load_gemspec(gemspec_name)

lib/wrong/chunk.rb

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ def glom(source)
7373
while sexp.nil? && line_index + c < lines.size
7474
begin
7575
@chunk = lines[line_index..line_index+c].join("\n")
76-
7776
capturing(:stderr) do # new RubyParser is too loud
7877
sexp = @parser.parse(@chunk)
7978
end

test/adapters/rspec1/Gemfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
source :rubygems
2+
13
here = File.expand_path(File.dirname(__FILE__))
24

35
gem "rspec", "~> 1.3", :require => "spec"
46
gem "rvm"
57
gem "bundler"
68
gem "rake"
79

8-
gemspec path: "#{here}/../../..", name: "wrong"
10+
gemspec :path => "#{here}/../../..", :name => "wrong"
911

test/adapters/rspec2/Gemfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
source :rubygems
2+
13
here = File.expand_path(File.dirname(__FILE__))
24

35
gem "rspec", "~> 2.0"
@@ -8,4 +10,4 @@ gem "rvm"
810
gem "bundler"
911
gem "rake"
1012

11-
gemspec path: "#{here}/../../..", name: "wrong"
13+
gemspec :path => "#{here}/../../..", :name => "wrong"

test/adapters/rspec_rails_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# called rspec-rails-generate.sh -- if you dare
1313

1414

15-
if RUBY_VERSION == "1.9.2" # too many issues with other versions
15+
if RUBY_VERSION >= "1.9.2" # too many issues with other versions
1616
describe "testing rspec-rails" do
1717

1818
[2].each do |rspec_version|

test/assert_advanced_test.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def assert_later(&p)
5050

5151
it "can compare two hashes" do
5252
assert { {1=>2} == {1=>2} }
53-
assert { {a:2} == {a:2} }
53+
unless RUBY_VERSION < "1.9"
54+
assert do
55+
{a:2} == {a:2}
56+
end
57+
end
5458
end
5559
end

test/failure_message_test.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require "./test/test_helper"
22
require "wrong/assert"
3+
require "wrong/chunk"
34
require "wrong/failure_message"
45

56
class BogusFormatter < Wrong::FailureMessage::Formatter
@@ -91,7 +92,7 @@ def message(options = {}, &block)
9192

9293
describe "#details" do
9394
def details(&block)
94-
@chunk = Chunk.from_block(block, 1)
95+
@chunk = Wrong::Chunk.from_block(block, 1)
9596
message.details
9697
end
9798

@@ -200,7 +201,7 @@ def inspect
200201
end
201202

202203
after do
203-
Terminal.width = 80
204+
Wrong::Terminal.width = 80
204205
end
205206

206207
it 'inspects its value' do

0 commit comments

Comments
 (0)