楼主: NewOccidental
2444 12

JRuby Cookbook [推广有奖]

  • 0关注
  • 6粉丝

已卖:1554份资源

副教授

31%

还不是VIP/贵宾

-

TA的文库  其他...

Complex Data Analysis

东西方金融数据分析

eBook with Data and Code

威望
0
论坛币
11734 个
通用积分
2.2450
学术水平
119 点
热心指数
115 点
信用等级
114 点
经验
8940 点
帖子
173
精华
10
在线时间
30 小时
注册时间
2006-9-19
最后登录
2022-11-3

楼主
NewOccidental 发表于 2015-4-12 06:53:24 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币


JRuby Cookbook


Book Description
If you're interested in JRuby, you probably don't need a turorial on Ruby, Rails, or Java - you just need to know how to get things done. This Cookbook offers practical solutions for using the Java implementation of the Ruby language, with targeted recipes for deploying Rails web applications on Java servers, integrating JRuby code with Java technologies, developing JRuby desktop applications with Java toolkits, and more.
Book Details
Publisher:        O'Reilly Media
By:        Justin Edelson, Henry Liu
ISBN:        978-0-59651-980-3
Year:        2008
Pages:        224
Language:        English
File size:        3.9 MB
File format:        PDF
eBook
Download:       

本帖隐藏的内容

JRuby Cookbook.pdf (3.69 MB, 需要: 20 个论坛币)


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Cookbook Book Cook Ruby COO interested practical recipes things Java

本帖被以下文库推荐

沙发
auirzxp(未真实交易用户) 学生认证  发表于 2015-6-21 03:22:13
提示: 作者被禁止或删除 内容自动屏蔽

藤椅
hyq2003(未真实交易用户) 发表于 2015-6-21 09:51:37

板凳
yuyike(未真实交易用户) 发表于 2015-6-21 10:36:50
Creating Mock Objects with Mocha

Problem

You want to test a Java class that has dependencies on other classes and want to insulate your tests from changes in the behavior of those other classes.


Solution

Use Mocha, a Ruby mocking and stubbing framework that is included with JtestR. Mocha allows you to create instances of Java interfaces and classes that exhibit a specific behavior. Mock objects can be used in any type of test supported by JtestR. In Example 7-8, Mocha is used to create a mock instance ofjava.util.Collection, which is passed to an instance of java.util.ArrayList. This test validates the behavior of the retainAll() method, specifically that it calls thecontains() method on the supplied Collection object the correct number of times.

Example 7-8. Unit test with dust and Mocha
  1. unit_tests do
  2.     test "that retainAll only calls contains" do
  3.         list = java.util.ArrayList.new
  4.         list << 'first'
  5.         list << 'second'
  6.         list << 'third'

  7.         other = java.util.Collection.new
  8.         other.expects(:contains).returns(true).times(3)

  9.         list.retainAll(other)
  10.     end
  11. end
复制代码





已有 1 人评分论坛币 收起 理由
Nicolle + 20 鼓励积极发帖讨论

总评分: 论坛币 + 20   查看全部评分

报纸
15559331297(未真实交易用户) 学生认证  发表于 2015-6-21 14:41:18
Testing Java Code with RSpec

Problem

You want to write behavior-orientated tests for your Java code.


Solution

Use JtestR’s support for the RSpec Behavior-Driven Development (BDD) framework. RSpec is actually composed of two different frameworks for writing tests: the Spec framework and the Story framework.

Spec framework

RSpec Spec tests describe the behavior of an object through a series of assertions about the behavior of the object. These assertions are referred to as examples. The Spec file in Example 7-5 describes the behavior of the java.util.HashSet class.

Example 7-5. RSpec Spec file for java.util.HashSet
  1. import java.util.HashSet

  2. describe HashSet do
  3.   before(:each) do
  4.     @set = HashSet.new
  5.   end

  6.   it "should be empty" do
  7.     @set.should be_empty
  8.   end

  9.   it "should be of size one after an item is added" do
  10.       @set << "foo"
  11.     @set.size.should == 1
  12.   end

  13.   it "should be of size one after an item is added twice" do
  14.       @set << "foo"
  15.       @set << "foo"
  16.     @set.size.should == 1
  17.   end

  18.   it "should be of size two after two items are added" do
  19.       @set << "foo"
  20.       @set << "bar"
  21.     @set.size.should == 2
  22.   end
  23. end
复制代码






已有 1 人评分论坛币 收起 理由
Nicolle + 20 鼓励积极发帖讨论

总评分: 论坛币 + 20   查看全部评分

地板
Crsky7(未真实交易用户) 发表于 2015-6-21 20:31:13
Unit Testing Java Code with Expectations

Problem

You want to test your Java code using a more concise syntax than is available from Java testing frameworks such as JUnit and TestNG and want to ensure you follow some testing best practices, specifically limiting the number of assertions per test to one.


Solution

Use JtestR’s support for the Expectations framework. Like dust, Expectations provides a domain-specific language (DSL) for writing tests. Unlike dust, Expectations does not use the standard Test/Unit assertion methods. Instead, each test makes an assertion about the return value of the test. Example 7-4 contains the same tests seen in prior recipes using Expectations.

Example 7-4. Unit testing with Expectations
  1. Expectations do
  2.     expect 0 do
  3.         list = java.util.ArrayList.new
  4.         list.size
  5.     end

  6.     expect 2 do
  7.         list = java.util.ArrayList.new
  8.         list << 'first'
  9.         list << 'second'
  10.         list.size
  11.     end

  12.     expect true do
  13.         list = java.util.ArrayList.new
  14.         list.empty
  15.     end

  16.     expect false do
  17.         list = java.util.ArrayList.new
  18.         list << 'first'
  19.         list << 'second'
  20.         list.empty
  21.     end
  22. end
复制代码





已有 1 人评分论坛币 收起 理由
Nicolle + 20 鼓励积极发帖讨论

总评分: 论坛币 + 20   查看全部评分

7
Nicolle(未真实交易用户) 学生认证  发表于 2015-6-28 07:14:06
提示: 作者被禁止或删除 内容自动屏蔽

8
Nicolle(未真实交易用户) 学生认证  发表于 2015-6-28 07:15:23
提示: 作者被禁止或删除 内容自动屏蔽

9
Lisrelchen(未真实交易用户) 发表于 2016-11-29 08:32:55
  1. Example 3-1. Calling Ruby from Java
  2. package org.jrubycookbook.ch03;

  3. import java.util.Collections;

  4. import org.jruby.Ruby;
  5. import org.jruby.javasupport.JavaEmbedUtils;

  6. public class RubyRunner {

  7.     public static void main(String[] args) {
  8.         // Create an instance of the JRuby runtime. The parameter to initalize()
  9.         // is a list of paths to be added to the Ruby load path.
  10.         Ruby runtime = JavaEmbedUtils.initialize(Collections.EMPTY_LIST);
  11.         runtime.evalScriptlet("puts 'hello world'");
  12.     }

  13. }

复制代码

10
Nicolle(未真实交易用户) 学生认证  发表于 2018-8-28 09:20:48
提示: 作者被禁止或删除 内容自动屏蔽

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-31 18:45