Skip to content

Commit

Permalink
Updates for RSpec 3
Browse files Browse the repository at this point in the history
Mostly simple syntax changes to the new `expect` style but also various
manual fixes where transpec didn't quite do the job. Normally around
the new `pending` semantics, and that the block form of `pending` is
deprecated.

Another big one was being explicit about the types of errors thrown.

There is still plenty of room for improvement here but at least we are
up and running on the latest/greatest RSpec vintage.
  • Loading branch information
benlovell committed Aug 21, 2015
1 parent 406ce28 commit 55f56c9
Show file tree
Hide file tree
Showing 211 changed files with 2,429 additions and 2,407 deletions.
8 changes: 4 additions & 4 deletions pom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

properties( 'its.j2ee' => 'j2ee*/pom.xml',
'its.osgi' => 'osgi*/pom.xml',
'rspec-core.version' => '2.14.2',
'rspec-core.version' => '3.3.2',
'jruby.basedir' => '${project.basedir}',
'minitest.version' => '5.4.1',
'ant.version' => '1.9.2',
Expand All @@ -61,15 +61,15 @@
'project.build.sourceEncoding' => 'utf-8',
'jruby-launcher.version' => '1.1.1',
'asm.version' => '5.0.3',
'rspec-expectations.version' => '2.14.0',
'rspec-expectations.version' => '3.3.1',
'base.javac.version' => '1.7',
'krypt.version' => '0.0.2.rc1',
'rdoc.version' => '4.1.0',
'polyglot.dump.pom' => 'pom.xml',
'rspec.version' => '2.14.1',
'rspec.version' => '3.3.0',
'base.java.version' => '1.7',
'polyglot.dump.readonly' => 'true',
'rspec-mocks.version' => '2.14.1',
'rspec-mocks.version' => '3.3.2',
'jruby.plugins.version' => '1.0.10',
'invoker.skip' => 'true',
'json.version' => '1.8.0',
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ DO NOT MODIFIY - GENERATED CODE
</site>
</distributionManagement>
<properties>
<rspec-core.version>2.14.2</rspec-core.version>
<rspec-core.version>3.3.2</rspec-core.version>
<polyglot.dump.readonly>true</polyglot.dump.readonly>
<its.j2ee>j2ee*/pom.xml</its.j2ee>
<jruby.basedir>${project.basedir}</jruby.basedir>
Expand All @@ -116,16 +116,16 @@ DO NOT MODIFIY - GENERATED CODE
<rake.version>10.1.0</rake.version>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
<jruby-launcher.version>1.1.1</jruby-launcher.version>
<rspec-expectations.version>2.14.0</rspec-expectations.version>
<rspec-expectations.version>3.3.1</rspec-expectations.version>
<asm.version>5.0.3</asm.version>
<its.osgi>osgi*/pom.xml</its.osgi>
<base.javac.version>1.7</base.javac.version>
<krypt.version>0.0.2.rc1</krypt.version>
<test-unit.version>3.0.3</test-unit.version>
<rdoc.version>4.1.0</rdoc.version>
<rspec.version>2.14.1</rspec.version>
<rspec.version>3.3.0</rspec.version>
<base.java.version>1.7</base.java.version>
<rspec-mocks.version>2.14.1</rspec-mocks.version>
<rspec-mocks.version>3.3.2</rspec-mocks.version>
<jruby.plugins.version>1.0.10</jruby.plugins.version>
<json.version>1.8.0</json.version>
<invoker.skip>true</invoker.skip>
Expand Down
13 changes: 7 additions & 6 deletions spec/compiler/general_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,8 @@ def blank?
end.new
') do |obj|
$~ = nil
obj.blank?.should == false
$~.should be_nil
expect(obj).not_to be_blank
expect($~).to be_nil
end
end

Expand Down Expand Up @@ -699,8 +699,8 @@ def self.remove; remove_method :gh1239; end
run("def foo; x = {1 => 2}; x.inject({}) do |hash, (key, value)|; hash[key.to_s] = value; hash; end; end; foo") {|result| expect(result).to eq({"1" => 2}) }
end

it "compiles very long code bodies", pending: "JIT support" do
# JRUBY-2246
it "compiles very long code bodies" do
skip "JRUBY-2246"
long_src = "a = 1\n"
5000.times { long_src << "a += 1\n" }
run(long_src) {|result| expect(result).to eq 5001 }
Expand Down Expand Up @@ -756,8 +756,9 @@ class AFromLocal < a
EOS
end

it "can compile large literal arrays and hashes", pending: "JIT support" do
# JRUBY-4757 and JRUBY-2621: can't compile large array/hash
it "can compile large literal arrays and hashes" do
skip "JRUBY-4757 and JRUBY-2621: can't compile large array/hash"

large_array = (1..10000).to_a.inspect
large_hash = large_array.clone
large_hash.gsub!('[', '{')
Expand Down
2 changes: 1 addition & 1 deletion spec/compiler/rubyscript_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
script1.add_import('my.java.import')

script2 = JRuby::Compiler::RubyScript.new("script2")
script2.imports.should_not include('my.java.import')
expect(script2.imports).not_to include('my.java.import')
end

end
12 changes: 7 additions & 5 deletions spec/compiler/skinnymethodadapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ def method_missing(name, *args)

insn_opcodes.each do |opcode|
opcode = opcode.downcase
instance_methods.should include(opcode)
expect(instance_methods).to include(opcode)
end

instance_methods.should include("go_to")
instance_methods.should include("voidreturn")
instance_methods.should include("instance_of")
instance_methods.should include("newobj")
expect(instance_methods).to include(
"go_to",
"voidreturn",
"instance_of",
"newobj"
)
end
end

30 changes: 15 additions & 15 deletions spec/java_integration/addons/io_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,69 +5,69 @@
let(:input_number){"1234567890"}
it "gets an IO from a java.io.InputStream" do
io = java.io.ByteArrayInputStream.new(input_number.to_java_bytes).to_io
io.class.should == IO
io.read(5).should == "12345"
expect(io.class).to eq(IO)
expect(io.read(5)).to eq("12345")
end

it "gets an IO from a java.io.OutputStream" do
output = java.io.ByteArrayOutputStream.new
io = output.to_io
io.class.should == IO
expect(io.class).to eq(IO)
io.write("12345")
io.flush
String.from_java_bytes(output.to_byte_array).should == "12345"
expect(String.from_java_bytes(output.to_byte_array)).to eq("12345")
end

it "is coercible to java.io.InputStream with IO#to_inputstream" do
file = File.open(__FILE__)
first_ten = file.read(10)
file.seek(0)
stream = file.to_inputstream
java.io.InputStream.should === stream
expect(java.io.InputStream).to be === stream

bytes = "0000000000".to_java_bytes
stream.read(bytes).should == 10
String.from_java_bytes(bytes).should == first_ten
expect(stream.read(bytes)).to eq(10)
expect(String.from_java_bytes(bytes)).to eq(first_ten)
end

it "is coercible to java.io.OutputStream with IO#to_outputstream" do
file = Tempfile.new("io_spec")
stream = file.to_outputstream
java.io.OutputStream.should === stream
expect(java.io.OutputStream).to be === stream

bytes = input_number.to_java_bytes
stream.write(bytes)
stream.flush
file.seek(0)
str = file.read(10)
str.should == String.from_java_bytes(bytes)
expect(str).to eq(String.from_java_bytes(bytes))
end

it "gets an IO from a java.nio.channels.Channel" do
input = java.io.ByteArrayInputStream.new(input_number.to_java_bytes)
channel = java.nio.channels.Channels.newChannel(input)
io = channel.to_io
io.class.should == IO
io.read(5).should == "12345"
expect(io.class).to eq(IO)
expect(io.read(5)).to eq("12345")

output = java.io.ByteArrayOutputStream.new
channel = java.nio.channels.Channels.newChannel(output)
io = channel.to_io
io.class.should == IO
expect(io.class).to eq(IO)
io.write("12345")
io.flush
String.from_java_bytes(output.to_byte_array).should == "12345"
expect(String.from_java_bytes(output.to_byte_array)).to eq("12345")
end

it "is coercible to java.nio.channels.Channel with IO#to_channel" do
file = Tempfile.new("io_spec")
channel = file.to_channel
java.nio.channels.Channel.should === channel
expect(java.nio.channels.Channel).to be === channel

bytes = java.nio.ByteBuffer.wrap(input_number.to_java_bytes)
channel.write(bytes)
file.seek(0)
str = file.read(10)
str.should == String.from_java_bytes(bytes.array)
expect(str).to eq(String.from_java_bytes(bytes.array))
end
end
7 changes: 5 additions & 2 deletions spec/java_integration/addons/object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ module Foo
class Foo
def initialize
java_import java.util.Properties
Properties.should == java.util.Properties
end

def props
Properties
end
end
Foo.new
expect(Foo.new.props).to eq(java.util.Properties)
end
end

Expand Down
18 changes: 9 additions & 9 deletions spec/java_integration/addons/stringio_addons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,38 @@
it "should be coercible to java.io.InputStream with StringIO#to_inputstream" do
file = StringIO.new("\xC3\x80abcdefghij")
stream = file.to_inputstream
java.io.InputStream.should === stream
expect(java.io.InputStream).to be === stream

stream.read.should == 0xc3
stream.read.should == 0x80
expect(stream.read).to eq(0xc3)
expect(stream.read).to eq(0x80)

bytes = "0000000000".to_java_bytes
stream.read(bytes).should == 10
String.from_java_bytes(bytes).should == 'abcdefghij'
expect(stream.read(bytes)).to eq(10)
expect(String.from_java_bytes(bytes)).to eq('abcdefghij')
end

it "should be coercible to java.io.OutputStream with StringIO#to_outputstream" do
file = StringIO.new
stream = file.to_outputstream
java.io.OutputStream.should === stream
expect(java.io.OutputStream).to be === stream

bytes = "1234567890".to_java_bytes
stream.write(bytes)
stream.flush
file.seek(0)
str = file.read(10)
str.should == String.from_java_bytes(bytes)
expect(str).to eq(String.from_java_bytes(bytes))
end

it "should be coercible to java.nio.channels.Channel with StringIO#to_channel" do
file = StringIO.new
channel = file.to_channel
java.nio.channels.Channel.should === channel
expect(java.nio.channels.Channel).to be === channel

bytes = java.nio.ByteBuffer.wrap("1234567890".to_java_bytes)
channel.write(bytes)
file.seek(0)
str = file.read(10)
str.should == String.from_java_bytes(bytes.array)
expect(str).to eq(String.from_java_bytes(bytes.array))
end
end
2 changes: 1 addition & 1 deletion spec/java_integration/addons/synchronized_class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ def expect_unsynchronized

it "should be includable only in classes" do
mod = Module.new
lambda { mod.class_eval { include JRuby::Synchronized } }.should raise_error(TypeError)
expect { mod.class_eval { include JRuby::Synchronized } }.to raise_error(TypeError)
end
end
2 changes: 1 addition & 1 deletion spec/java_integration/addons/throwable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
it "implements backtrace" do
ex = java.lang.Exception.new
trace = nil
lambda {trace = ex.backtrace}.should_not raise_error
expect {trace = ex.backtrace}.not_to raise_error
expect(trace).to eq(ex.stack_trace.map(&:to_s))
end

Expand Down
Loading

0 comments on commit 55f56c9

Please sign in to comment.