Skip to content

Commit a632d19

Browse files
author
monkstone
committed
fix spec, regularize Bar class
1 parent 7f87a54 commit a632d19

File tree

6 files changed

+65
-23
lines changed

6 files changed

+65
-23
lines changed

extensions/basic/jruby-ext/Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ end
2525
desc 'Test'
2626
task :test do
2727
sh 'jruby ../test/basic_test.rb'
28+
sh 'jruby ../test/bar_spec_test.rb'
2829
end
2930

3031
desc 'clean'

extensions/basic/jruby-ext/src/main/java/com/purbon/Bar.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,28 @@ public Bar(Ruby ruby, RubyClass metaclass) {
2121
super(ruby, metaclass);
2222
}
2323

24-
@JRubyMethod(module = true, name = {"shout", "say"})
25-
public static RubyString shout(ThreadContext context, IRubyObject self) {
24+
@JRubyMethod(name = {"shout", "say"})
25+
public IRubyObject shout_ruby(ThreadContext context) {
2626
return context.runtime.newString("Hello World!");
2727
}
2828

29-
@JRubyMethod(module = true, name = "add")
30-
public IRubyObject add(ThreadContext context, IRubyObject a, IRubyObject b) {
29+
@JRubyMethod(name = "add")
30+
public IRubyObject add_ruby(ThreadContext context, IRubyObject a, IRubyObject b) {
3131
return a.callMethod(context, "+", b);
3232
}
3333

34-
@JRubyMethod(module = true, name = "sub")
35-
public IRubyObject sub(ThreadContext context, IRubyObject a, IRubyObject b) {
34+
@JRubyMethod(name = "subtract")
35+
public IRubyObject sub_ruby(ThreadContext context, IRubyObject a, IRubyObject b) {
3636
return a.callMethod(context, "-", b);
3737
}
3838

39-
@JRubyMethod(module = true, name = "div")
39+
@JRubyMethod(name = "divide")
4040
public IRubyObject div(ThreadContext context, IRubyObject a, IRubyObject b) {
4141
return a.callMethod(context, "/", b);
4242
}
4343

44-
@JRubyMethod(module = true, name = "plus")
45-
public IRubyObject plus(ThreadContext context, IRubyObject a, IRubyObject b) {
44+
@JRubyMethod(name = "multiply")
45+
public IRubyObject mult(ThreadContext context, IRubyObject a, IRubyObject b) {
4646
return a.callMethod(context, "*", b);
4747
}
4848

extensions/basic/jruby-ext/src/main/java/com/purbon/BasicService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
/**
1313
* This class is used when to run the instantiation and load
14-
* of all the related modules and classes defined here.
14+
* of all the related modules and classes are defined here.
1515
* Created by purbon on 24/08/15.
1616
*/
1717
public class BasicService implements BasicLibraryService {
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,39 @@
1-
require "spec_helper"
1+
require_relative 'spec_helper'
22

33
##
44
# Describe behaviour created in the JRuby Exception
55
# Class named Bar. This class include common basic
66
# things you can do with Classes as in JRuby Extensions
7-
# mecanism.
7+
# mechanism.
88
##
99
describe Bar do
1010

1111
context "simple methods" do
12-
it 'shout return an string' do
12+
it 'shout return a string' do
1313
expect(subject.shout).to eq("Hello World!");
1414
end
1515

16-
it 'say return an string' do
16+
it 'say return a string' do
1717
expect(subject.say).to eq("Hello World!");
1818
end
1919
end
2020

21-
context "aritmetic operations" do
21+
context "arithmetic operations" do
2222

2323
it "add two numbers" do
2424
expect(subject.add(3, 2)).to eq(5)
2525
end
2626

2727
it "substract two numbers" do
28-
expect(subject.sub(3, 2)).to eq(1)
28+
expect(subject.subtract(3, 2)).to eq(1)
2929
end
3030

3131
it "divide two numbers" do
32-
expect(subject.div(4, 2)).to eq(2)
32+
expect(subject.divide(4, 2)).to eq(2)
3333
end
3434

3535
it "multiply two numbers" do
36-
expect(subject.plus(4, 2)).to eq(8)
36+
expect(subject.multiply(4, 2)).to eq(8)
3737
end
38-
3938
end
40-
41-
end
39+
end
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2-
require "basic"
1+
require_relative '../lib/basic'
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
gem 'minitest' # don't use bundled minitest
2+
require 'java'
3+
require 'minitest/autorun'
4+
require 'minitest/pride'
5+
require_relative '../lib/basic'
6+
7+
# Test Bar class functionality using regular
8+
# Minitest::Test albeit with jruby runtime
9+
10+
class BarTest < Minitest::Test
11+
attr_reader :bar
12+
def setup
13+
@bar = Bar.new
14+
end
15+
16+
def test_new
17+
assert bar.instance_of? Bar
18+
end
19+
20+
def test_shout
21+
assert bar.shout == 'Hello World!'
22+
end
23+
24+
def test_say
25+
assert bar.say == 'Hello World!'
26+
end
27+
28+
def test_add
29+
assert bar.add(3, 2) == 5
30+
end
31+
32+
def test_subtract
33+
assert bar.subtract(3, 2) == 1
34+
end
35+
36+
def test_divide
37+
assert bar.divide(3, 2) == 1
38+
end
39+
40+
def test_multiply
41+
assert bar.multiply(4, 2) == 8
42+
end
43+
end
44+

0 commit comments

Comments
 (0)