先日、
Google 日本語入力
がリリースされましたが
Windows 版
のみかとおもいきや


こちらで、マルチプラットフォーム版も公開されています。

mozc

将来的に chrome にも搭載できるようです。
このあたりは抜かりがないな。

インストールガイドに従って
UNR にインストールしてみる。

LinuxBuildInstructions

小生は、dbpkg を生成して
インストールする方法を選択した。

dbpkg の実行後に
ibus を再起動すると

設定 -> インプットメソッド -> インプットメソッドの選択 -> 日本語 ->
で mozc が選択できるようになる。

日本語キー配列と
USキー配列が選択できるようだが
ここは、素直に日本語キー配列を選択。

これで、出先でメール打つのが
楽になればいいなぁ。

UNR (Ubuntu NetBook Remix)10.04 LTS with D02HW

の続き。

前回のエントリで
OS起動後に
e-mobile
のアダプタを差しても認識されない問題についてとりあげたが

解決策が見出せたのでメモ。

HUAWEI E220 3G HSDPA USB MODEM Support in Linux

より

huawei.tar.bz2

を入手する。

で展開してディレクトリに入る。

#bzip2 -d huawei.tar.bz2
#tar -xf huawei.tar
#cd huawei


UNR10.04LTSで使うために少し編集する。

ます、
Makefile

udevcontrol reload_rules

udevadm control --reload-rules
に書き換える。


次に、

file/huawei-mobile.sh

uname -a
/sbin/modprobe usbserial vendor=0x12d1 product=0x1003

uname -a
/sbin/modprobe option
/sbin/modprobe usbserial vendor=0x12d1 product=0x1003
に書き換える。

で、
#sudo make install_ubuntu
でインストール。

これで
udev
の設定が変更される。

試しに、アダプタを差してみる。

#dmesg
で状態を確認。

以下のようになる。
(関連箇所のみ抜粋)

---------------------------------------

[ 68.344040] usb 2-2: new full speed USB device using uhci_hcd and address 3
[ 68.508097] usb 2-2: configuration #1 chosen from 1 choice
[ 68.554052] scsi6 : SCSI emulation for USB Mass Storage devices
[ 68.562208] usb-storage: device found at 3
[ 68.562214] usb-storage: waiting for device to settle before scanning
[ 73.562157] usb-storage: device scan complete
[ 73.565152] scsi 6:0:0:0: CD-ROM HUAWEI Mass Storage 2.31 PQ: 0 ANSI: 2
[ 73.598124] sr0: scsi-1 drive
[ 73.598134] Uniform CD-ROM driver Revision: 3.20
[ 73.598414] sr 6:0:0:0: Attached scsi CD-ROM sr0
[ 73.598576] sr 6:0:0:0: Attached scsi generic sg3 type 5
[ 73.705808] usbcore: registered new interface driver usbserial
[ 73.707597] USB Serial support registered for generic
[ 73.709936] usbcore: registered new interface driver usbserial_generic
[ 73.709944] usbserial: USB Serial Driver core
[ 73.722312] USB Serial support registered for GSM modem (1-port)
[ 73.724502] option 2-2:1.0: GSM modem (1-port) converter detected
[ 73.728832] usb 2-2: GSM modem (1-port) converter now attached to ttyUSB0
[ 73.728880] option 2-2:1.1: GSM modem (1-port) converter detected
[ 73.733294] usb 2-2: GSM modem (1-port) converter now attached to ttyUSB1
[ 73.733378] usbcore: registered new interface driver option
[ 73.733383] option: v0.7.2:USB Driver for GSM modems

---------------------------------------

/dev/ttyUSB0
が現れる。

あとは、
gnome-ppp
などで接続してやればOK。

以下、接続時のログ。

---------------------------------------

--> WvDial: Internet dialer version 1.60
--> Cannot get information for serial port.
--> Initializing modem.
--> Sending: ATZ
ATZ
OK
--> Sending: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
OK
--> Modem initialized.
--> Sending: ATM1L3DT*99***1#
--> Waiting for carrier.
ATM1L3DT*99***1#
CONNECT
--> Carrier detected. Waiting for prompt.
--> Don't know what to do! Starting pppd and hoping for the best.
--> Starting pppd at Mon May 24 10:18:42 2010
--> Pid of pppd: 2010
--> Using interface ppp0

(以下省略)

---------------------------------------

以前のエントリ
で紹介したが

eeePC

e-mobile
のアダプタ(D02HW)
を使用しているが、

PCの電源を入れる前からUSBアダプタを
差していれば問題なく
gnome-ppp
から利用できるが、

PCの電源を入れてからUSBアダプタを
差しても
/dev/ttyUSB0
にデバイスが現れないため
モデムとして利用できない
状態になっている事に気づいた。

以前の
UNR9.10
のころは
このあたりも問題なく
動いていたので
UNR10.04LTSにアップグレード
したのが原因のようだ。


以下、アダプタを差した状態で
ブートしたときの状態。

dmesg
内の関連メッセージを抜粋。

CDーROM

モデムとして
認識されていることがわかる。

---------------------------------------------------

[ 7.270049] usb-storage: device scan complete
[ 7.273029] scsi 5:0:0:0: CD-ROM HUAWEI Mass Storage 2.31 PQ: 0 ANSI: 2
[ 7.289986] sr0: scsi-1 drive
[ 7.289992] Uniform CD-ROM driver Revision: 3.20
[ 7.290218] sr 5:0:0:0: Attached scsi CD-ROM sr0
[ 7.290485] sr 5:0:0:0: Attached scsi generic sg3 type 5
[ 8.483504] udev: starting version 151

(中略)

[ 10.025951] USB Serial support registered for GSM modem (1-port)
[ 10.026624] option 2-2:1.0: GSM modem (1-port) converter detected
[ 10.027203] usb 2-2: GSM modem (1-port) converter now attached to ttyUSB0
[ 10.027239] option 2-2:1.1: GSM modem (1-port) converter detected
[ 10.027706] usb 2-2: GSM modem (1-port) converter now attached to ttyUSB1
[ 10.027848] usbcore: registered new interface driver option
[ 10.027854] option: v0.7.2:USB Driver for GSM modems

---------------------------------------------------

続いて
hal-device
の表示結果。

---------------------------------------------------

33: udi = '/org/freedesktop/Hal/devices/usb_device_12d1_1003_noserial_if1_serial_usb_0'
linux.hotplug_type = 2 (0x2) (int)
linux.subsystem = 'tty' (string)
serial.originating_device = '/org/freedesktop/Hal/devices/usb_device_12d1_1003_noserial_if1' (string)
serial.device = '/dev/ttyUSB1' (string)
serial.port = 0 (0x0) (int)
serial.type = 'usb' (string)
info.subsystem = 'tty' (string)
info.product = 'E220 HSDPA Modem / E270 HSDPA/HSUPA Modem' (string)
linux.sysfs_path = '/sys/devices/pci0000:00/0000:00:1d.0/usb2/2-2/2-2:1.1/ttyUSB1/tty/ttyUSB1' (string)
info.parent = '/org/freedesktop/Hal/devices/usb_device_12d1_1003_noserial_if1' (string)
info.udi = '/org/freedesktop/Hal/devices/usb_device_12d1_1003_noserial_if1_serial_usb_0' (string)
info.category = 'serial' (string)
info.capabilities = { 'serial' } (string list)
linux.device_file = '/dev/ttyUSB1' (string)

34: udi = '/org/freedesktop/Hal/devices/usb_device_12d1_1003_noserial_if0_serial_usb_0'
linux.hotplug_type = 2 (0x2) (int)
linux.subsystem = 'tty' (string)
serial.originating_device = '/org/freedesktop/Hal/devices/usb_device_12d1_1003_noserial_if0' (string)
serial.device = '/dev/ttyUSB0' (string)
serial.port = 0 (0x0) (int)
serial.type = 'usb' (string)
info.subsystem = 'tty' (string)
info.product = 'E220 HSDPA Modem / E270 HSDPA/HSUPA Modem' (string)
linux.sysfs_path = '/sys/devices/pci0000:00/0000:00:1d.0/usb2/2-2/2-2:1.0/ttyUSB0/tty/ttyUSB0' (string)
info.parent = '/org/freedesktop/Hal/devices/usb_device_12d1_1003_noserial_if0' (string)
info.udi = '/org/freedesktop/Hal/devices/usb_device_12d1_1003_noserial_if0_serial_usb_0' (string)
info.category = 'serial' (string)
info.capabilities = { 'serial', 'modem' } (string list)
linux.device_file = '/dev/ttyUSB0' (string)
modem.command_sets = { 'GSM-07.07', 'GSM-07.05' } (string list)


117: udi = '/org/freedesktop/Hal/devices/usb_device_12d1_1003_noserial'
info.udi = '/org/freedesktop/Hal/devices/usb_device_12d1_1003_noserial' (string)
usb_device.bus_number = 2 (0x2) (int)
linux.hotplug_type = 2 (0x2) (int)
usb_device.linux.sysfs_path = '/sys/devices/pci0000:00/0000:00:1d.0/usb2/2-2' (string)
usb_device.configuration_value = 1 (0x1) (int)
usb_device.num_configurations = 1 (0x1) (int)
usb_device.num_interfaces = 3 (0x3) (int)
usb_device.device_class = 0 (0x0) (int)
usb_device.device_subclass = 0 (0x0) (int)
usb_device.device_protocol = 0 (0x0) (int)
usb_device.vendor_id = 4817 (0x12d1) (int)
usb_device.product_id = 4099 (0x1003) (int)
usb_device.vendor = 'Huawei Technologies Co., Ltd.' (string)
usb_device.product = 'E220 HSDPA Modem / E270 HSDPA/HSUPA Modem' (string)
usb_device.device_revision_bcd = 0 (0x0) (int)
info.subsystem = 'usb_device' (string)
info.product = 'E220 HSDPA Modem / E270 HSDPA/HSUPA Modem' (string)
linux.sysfs_path = '/sys/devices/pci0000:00/0000:00:1d.0/usb2/2-2' (string)
info.parent = '/org/freedesktop/Hal/devices/usb_device_1d6b_1_0000_00_1d_0' (string)
usb_device.num_ports = 0 (0x0) (int)
info.linux.driver = 'usb' (string)
usb_device.max_power = 500 (0x1f4) (int)
usb_device.speed = 12 (double)
usb_device.linux.device_number = 2 (0x2) (int)
usb_device.is_self_powered = false (bool)
usb_device.can_wake_up = true (bool)
usb_device.version = 1.1 (double)
linux.device_file = '/dev/bus/usb/002/002' (string)
info.vendor = 'Huawei Technologies Co., Ltd.' (string)
linux.subsystem = 'usb' (string)

---------------------------------------------------

要は、ブート後にアダプタを差し直した際に
この状態を際限できれば良いということになる。

おそらく
udev
まわりの設定を見直すことになるだろう。


今日は時間がなくなったのでここまで。


既に各メディより報道されているので
ご存知の方も多いかと思いますが

宮崎県では口蹄疫の拡大感染により、畜産業に多大な被害が発生しております。

宮崎県の公式発表

小生も微力ながら何か力になれないかと思い、情報を収集していたのですが
その際に

ミヤチク 農村協働公舎



の存在を知りました。

良質な農産物を良心的な価格で販売されておられます。

生産者の方が丹精込めて育てられた農産物をいただくことが
なによりの手助けになるのではないかとの思いから
少しではありますが発注させていただきました。


★ポークジャーキー20g×5袋 
 価格: 1,000 円

★ポークソーセージ250g×3個
 価格: 1,200 円

★たべごろフランク130g×5袋 
 価格: 1,100 円

★粗挽きウインナー100g×3袋
 価格: 1,000 円

★N-803 ハムソーセージセット
 ロースハムスモーク150g×1、
 ヒレハム1本分、
 粗挽きウインナー100g×1、
 ペッパーボンレスハム(ハーフ)130g×1、
 ボンレスハムハーフ130g×1
 価格: 4,000 円



\5,000以上のオーダーで送料はサービスしていただけるとのこと。

是非、ご覧いただいて
一人でも多くの方にご利用していただければ
と思います。

Twitter もどきを JRuby on Rails で書いてみる Part4

の続き。

前回までは、
データーベースの設定と
HTTP サーバの起動まで完了した。

いよいよ、アプリの実装に入っていく。

まず

name title content
を属性に持った
Post
クラスを生成する。

#jruby -S script/generate scaffold Post name:string title:string content:string

以下、結果出力。

-------------------------

exists app/models/
exists app/controllers/
exists app/helpers/
create app/views/posts

(中略)

create test/fixtures/posts.yml
create db/migrate
create db/migrate/20100522113845_create_posts.rb

-------------------------

#rake db:migrate

データーベースにテーブルを生成する。

以下、結果出力。

-------------------------

== CreatePosts: migrating ====================================================
-- create_table(:posts)
-> 0.0180s
-> 0 rows
== CreatePosts: migrated (0.0210s) ===========================================

-------------------------

#mysql -u root -p -D twfake_develop

データーベースに生成された
テーブルを確認してみる。

以下、結果出力。

-------------------------
mysql> show tables;
+--------------------------+
| Tables_in_twfake_develop |
+--------------------------+
| posts |
| schema_migrations |
+--------------------------+

mysql> describe posts;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | YES | | NULL | |
| title | varchar(255) | YES | | NULL | |
| content | varchar(255) | YES | | NULL | |
| created_at | datetime | YES | | NULL | |
| updated_at | datetime | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+

以下、結果出力。

-------------------------

コードとテーブルが作成されたのを確認したので
HTTP サーバーを起動してみる。

#jruby -S script/server

HTTP アドレスは
http://localhost:3000/posts
のように指定する。

データーベースに対して
参照・新規追加・編集・削除
の機能を持ったページが生成されている
ことが確認できる。


日本語の入力・表示についても問題なく実行できている。


JRuby 徹底入門/株式会社イーシー・ワン

¥2,604
Amazon.co.jp

基礎からのMySQL [基礎からのシリーズ] (プログラマの種シリーズ)/西沢 夢路

¥3,129
Amazon.co.jp

10日でおぼえる Ruby on Rails入門教室/arton

¥2,940
Amazon.co.jp

Twitter もどきを JRuby on Rails で書いてみる Part3

の続き。


とりあえず、何か表示させてみよう。

#jruby -S script/generate controller home index

--------------------------------

gem install jruby-openssl for full support.
exists app/controllers/
exists app/helpers/
create app/views/home
exists test/functional/
create test/unit/helpers/
create app/controllers/home_controller.rb
create test/functional/home_controller_test.rb
create app/helpers/home_helper.rb
create test/unit/helpers/home_helper_test.rb
create app/views/home/index.html.erb

--------------------------------

ちょっとビューをいじってみる。


app/views/home/index.html.erb
の中身。

"Hello Rails" を追加。
--------------------------------

Home#index


Find me in app/views/home/index.html.erb



Hello Rails



--------------------------------


で、サーバーを起動する。

#jruby -S script/server


--------------------------------
=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
JRuby limited openssl loaded. http://jruby.org/openssl
gem install jruby-openssl for full support.
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2010-05-22 19:31:06] INFO WEBrick 1.3.1
[2010-05-22 19:31:06] INFO ruby 1.8.7 (2010-05-12) [java]
[2010-05-22 19:31:11] INFO WEBrick::HTTPServer#start: pid=6826 port=3000
--------------------------------


ブラウザから、
rails が動いているホストにアクセス。

例えば、 http://localhost:3000/home

$Digital Lab

index.html.erb
の内容が表示されていることがわかる。

サーバーの停止は、
コンソール上で ctrl + c






JRuby on Railsシステム構築入門 (DB Magazine SELECTION)/橋本 吉治

¥2,814
Amazon.co.jp

JRuby 徹底入門/株式会社イーシー・ワン

¥2,604
Amazon.co.jp

Twitter もどきを JRuby on Rails で書いてみる Part2

の続き。

JDBC でコネクトするため
次のようにしてやる。


#jruby -S script/generate jdbc


以下、結果メッセージ。

-----------------------------------

exists config/initializers
identical config/initializers/jdbc.rb
exists lib/tasks
identical lib/tasks/jdbc.rake

-----------------------------------


で、
rails で使用する db を
以下のように生成する。

#jruby -S rake db:create:all

mysql 上にデーターベースが生成されていることを
確認する。

#mysqlshow -u root -p

結果メッセージから
twfake 用に3つのデーターベースが生成されていることがわかる。

-----------------------------------

Enter password:
+--------------------+
| Databases |
+--------------------+
| information_schema |
| mysql |
| twfake_develop |
| twfake_production |
| twfake_test |
+--------------------+

-----------------------------------


以下、
現時点での
database.yml
の中身。

-----------------------------------

development:
adapter: jdbcmysql
encoding: utf8
reconnect: false
hostname: localhost
database: twfake_develop
pool: 5
username: root
password: *******


# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: jdbcmysql
encoding: utf8
reconnect: false
hostname: localhost
database: twfake_test
pool: 5
username: root
password: *******

production:
adapter: jdbcmysql
encoding: utf8
hostname: localhost
database: twfake_production
username: root
password: *******

-----------------------------------

基礎からのMySQL [基礎からのシリーズ] (プログラマの種シリーズ)/西沢 夢路

¥3,129
Amazon.co.jp

3ステップでしっかり学ぶ MySQL入門 (今すぐ使えるかんたんプラス)/山田 祥寛

¥2,499
Amazon.co.jp

Twitter もどきを JRuby on Rails で書いてみる Part1

の続き。


では、とりあえず

#rails twfake -d mysql

----------------------------------
create
create app/controllers
create app/helpers
create app/models

(中略)

create log/production.log
create log/development.log
create log/test.log

----------------------------------

で作成されたディレクトリを確認。

#ls

----------------------------------
twfake
----------------------------------


#tree -d twfake

----------------------------------
twfake
|-- app
| |-- controllers
| |-- helpers
| |-- models
| `-- views
| `-- layouts
|-- config
| |-- environments
| |-- initializers
| `-- locales
|-- db
|-- doc
|-- lib
| `-- tasks
|-- log
|-- public
| |-- images
| |-- javascripts
| `-- stylesheets
|-- script
| `-- performance
|-- test
| |-- fixtures
| |-- functional
| |-- integration
| |-- performance
| `-- unit
|-- tmp
| |-- cache
| |-- pids
| |-- sessions
| `-- sockets
`-- vendor
`-- plugins

----------------------------------

こんな感じでディレクトリが生成される。

mysql 
に合わせた設定がされてあるので
内容を確認する。

#less twfake/config/database.yml

----------------------------------
development:
adapter: mysql
encoding: utf8
reconnect: false
database: twfake_development
pool: 5
username: root
password:
socket: /var/run/mysqld/mysqld.sock

(以下略)
----------------------------------

開発用データーベースはこんな感じの設定。

続いて
テスト用と、プロダクション用の
データーベース設定も
同様に記述されているはず。


続いてデーターベースを作成する。

#rake db:create

が、ここでエラー発生。

----------------------------------
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
rake aborted!
no such file to load -- mysql
----------------------------------


Ruby 用の mysql ドライバがないので
インストールしろといわれる。


ここは指示に従い

#gem install mysql

だが、またしてもエラー。

----------------------------------
JRuby limited openssl loaded. http://jruby.org/openssl
gem install jruby-openssl for full support.
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.

jruby-1.5.0/bin/jruby extconf.rb
WARNING: JRuby does not support native extensions or the `mkmf' library.
Check http://kenai.com/projects/jruby/pages/Home for alternatives.
extconf.rb:30: undefined method `with_config' for main:Object (NoMethodError)

----------------------------------

いわれたとりに、

http://kenai.com/projects/jruby/pages/Home

で情報収集。

ちなみに、こんないいサイトあったの知りませんでした。
たまには、エラーに遭遇するのもいいもんだ。


今日は、時間がなくなったので
ここまで。

JRuby on Railsシステム構築入門 (DB Magazine SELECTION)/橋本 吉治

¥2,814
Amazon.co.jp

10日でおぼえる Ruby on Rails入門教室/arton

¥2,940
Amazon.co.jp

Ruby on Rails入門―優しいRailsの育て方/西 和則

¥2,940
Amazon.co.jp

ちょっとした思い付きで

Twitter (のようなもの)


JRuby on Rails

で実装してみることに。

OS は、Ubuntu8.0.4


ますは、Jruby のバージョンを確認。


#jruby -v

jruby 1.5.0 (ruby 1.8.7 patchlevel 249) (2010-05-12 6769999) (Java HotSpot(TM) Client VM 1.6.0_18) [i386-java]




で、 Rails を
インストール。

#gem install rails

-------------------------------------------

JRuby limited openssl loaded. http://jruby.org/openssl
gem install jruby-openssl for full support.
Successfully installed activesupport-2.3.5
Successfully installed activerecord-2.3.5
Successfully installed rack-1.0.1
Successfully installed actionpack-2.3.5
Successfully installed actionmailer-2.3.5
Successfully installed activeresource-2.3.5
Successfully installed rails-2.3.5
7 gems installed

---------------------------------------------


続いて、
データーベースをインストール。
ここでは、

MYSQL

を使う。


インストールされていなければ
以下のように取得する。

#sudo apt-get install mysql-server-5.0

上記のように
apt
からインストールした場合
自動的に起動されるようだ。


#ps -ax | grep mysql

とすると


-------------------------------------

6749 ? S 0:00 /bin/sh /usr/bin/mysqld_safe
6879 ? Sl 0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --port=3306 --socket=/var/run/mysqld/mysqld.sock
6880 ? S 0:00 logger -p daemon.err -t mysqld_safe -i -t mysqld
6978 pts/0 R+ 0:00 grep mysql


-------------------------------------



または、


#sudo /etc/init.d/mysql status


-------------------------------------

* /usr/bin/mysqladmin Ver 8.41 Distrib 5.0.51a, for debian-linux-gnu on i486
Copyright (C) 2000-2006 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Server version 5.0.51a-3ubuntu5.5
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/run/mysqld/mysqld.sock
Uptime: 2 min 57 sec

-------------------------------------

動いているのがわかる。


動いてなければ

#sudo /etc/init.d/mysql start

で動きだす。

止めるときは

#sudo /etc/init.d/mysql stop



で、動いているDBに接続。


#mysql -u root -p

パスワード入力を求められるので入力。
※Mysql の root ユーザー の パスワードを入力する。

-------------------------------------

Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.0.51a-3ubuntu5.5 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

-------------------------------------


接続できるのを確認したら

quit

で mysql プロンプトから抜ける。


とりあえず
きょうはここまで。


基礎からのMySQL [基礎からのシリーズ] (プログラマの種シリーズ)/西沢 夢路

¥3,129
Amazon.co.jp

Ruby on Rails入門―優しいRailsの育て方/西 和則

¥2,940
Amazon.co.jp

たのしいRuby 第2版 Rubyではじめる気軽なプログラミング/高橋 征義

¥2,730
Amazon.co.jp

Java

のクラスのテストコードを Java でなく

Jruby

で書いてみる。

あえて LL で書くのは、
テストコード量の削減とコンパイル時間の削減が目的。


EJB3
のクラスなんかのテストケースを書くのに
結構いいかもしれない。


ますは、非テスト対象のクラスから

Hoge.java
--------------------------------------------

public class Hoge{

 public String sayHello(String yourname){
  return "Hello " + yourname;
 }

 public int add(int x,int y){
  return x + y;
 }
}

--------------------------------------------


で、つぎはテストコード。


TestHoge.rb
--------------------------------------------
require 'java'

require 'test/unit'

include_class 'Hoge'

class HogeTest < Test::Unit::TestCase

 def setup
  @target = Hoge.new
 end

 def test_sayHello
  res = @target.sayHello "Fuga"
  assert_equal "Hello Fuga",res
 end

 def test_add
  res = @target.add 1,2
  assert_equal 3,res
 end
end

--------------------------------------------


で、実行。

# jruby HogeTest.rb


以下、実行結果。

--------------------------------------------
Loaded suite HogeTest
Started
..
Finished in 0.017 seconds.

2 tests, 2 assertions, 0 failures, 0 errors
--------------------------------------------


ここでは触れていないが、
Java のリフレクションなんかも
問題なく使える。

テストコードは書きたいが
手間はかけたくないという方にはお勧め。

たのしいRuby 第2版 Rubyではじめる気軽なプログラミング/高橋 征義

¥2,730
Amazon.co.jp

現場の仕事がバリバリ進む ソフトウェアテスト手法/高橋 寿一

¥2,499
Amazon.co.jp