この本で言っているユニットテストとは?
→オブジェクト間の振る舞いを表すテスト。
あるメソッドを呼んで、それがどういった戻り値を返すといったことをテストするのではなく、
あるメソッドにオブジェクトを渡した時にそれが内部でどう扱われているかといったことをテストする。
振る舞いをテストするといった時にテストコードがスパゲッティになることを防いで、
やるテストをはっきりさせること。
メソッド名で振る舞いを表せれば、テスト内容も振る舞いに寄って行きそうだよね。
ユースケースシナリオ
ユースケースシナリオとユニットテストの間でこのデータがどこのテーブルと関連づいているかは
テストする前にはっきりさせておく必要がある。
列車事故が悪いのは、
・クラスの内部構造まで把握しなければいけないこと
・呼び出し元が期待した結果を一発で返していないこと
・テストを保守するときに難しくなる
複数の責務がある場合にはその責務は全て分割されているのであれば、
それをまとめる行為に別の名前があるから、その名前がメソッド名になる。
2014年5月25日日曜日
2014年5月6日火曜日
Ruby on RailsからMySQL接続に発生するエラー
Ruby on RailsからMySQLに接続しようとして下記エラーが発生
MySQLをインストールしてから再度実行でうまくいきました。(参考)
libmysqlclient.18.dylibがないと言われた場合。
参考
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[xxxxxxxx@yyyyyyyy zzzzz]$rake environment -v -t RAILS_ENV=development db:schema:dump | |
Could not find gem 'mysql2 (>= 0) ruby' in the gems available on this machine. | |
Run `bundle install` to install missing gems. | |
[xxxxxxxx@yyyyyyyy zzzzz]$bundle install | |
Fetching gem metadata from https://rubygems.org/........... | |
Fetching additional metadata from https://rubygems.org/.. | |
Resolving dependencies... | |
Using rake (10.3.1) | |
Using i18n (0.6.9) | |
Using minitest (4.7.5) | |
Using multi_json (1.10.0) | |
Using thread_safe (0.3.3) | |
Using tzinfo (0.3.39) | |
Using activesupport (4.0.4) | |
Using builder (3.1.4) | |
Using erubis (2.7.0) | |
Using rack (1.5.2) | |
Using rack-test (0.6.2) | |
Using actionpack (4.0.4) | |
Using mime-types (1.25.1) | |
Using polyglot (0.3.4) | |
Using treetop (1.4.15) | |
Using mail (2.5.4) | |
Using actionmailer (4.0.4) | |
Using activemodel (4.0.4) | |
Using activerecord-deprecated_finders (1.0.3) | |
Using arel (4.0.2) | |
Using activerecord (4.0.4) | |
Using bundler (1.5.2) | |
Using coffee-script-source (1.7.0) | |
Using execjs (2.0.2) | |
Using coffee-script (2.2.0) | |
Using thor (0.19.1) | |
Using railties (4.0.4) | |
Using coffee-rails (4.0.1) | |
Using hike (1.2.3) | |
Using jbuilder (1.5.3) | |
Using jquery-rails (3.1.0) | |
Using json (1.8.1) | |
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. | |
/Users/rmswimkkrr/.rvm/rubies/ruby-2.0.0-p353/bin/ruby extconf.rb | |
checking for ruby/thread.h... yes | |
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes | |
checking for rb_thread_blocking_region()... yes | |
checking for rb_wait_for_single_fd()... yes | |
checking for rb_hash_dup()... yes | |
checking for rb_intern3()... yes | |
checking for mysql_query() in -lmysqlclient... no | |
checking for main() in -lm... yes | |
checking for mysql_query() in -lmysqlclient... no | |
checking for main() in -lz... yes | |
checking for mysql_query() in -lmysqlclient... no | |
checking for main() in -lsocket... no | |
checking for mysql_query() in -lmysqlclient... no | |
checking for main() in -lnsl... no | |
checking for mysql_query() in -lmysqlclient... no | |
checking for main() in -lmygcc... no | |
checking for mysql_query() in -lmysqlclient... no | |
*** extconf.rb failed *** | |
Could not create Makefile due to some reason, probably lack of necessary | |
libraries and/or headers. Check the mkmf.log file for more details. You may | |
need configuration options. | |
Provided configuration options: | |
--with-opt-dir | |
--without-opt-dir | |
--with-opt-include | |
--without-opt-include=${opt-dir}/include | |
--with-opt-lib | |
--without-opt-lib=${opt-dir}/lib | |
--with-make-prog | |
--without-make-prog | |
--srcdir=. | |
--curdir | |
--ruby=/Users/rmswimkkrr/.rvm/rubies/ruby-2.0.0-p353/bin/ruby | |
--with-mysql-dir | |
--without-mysql-dir | |
--with-mysql-include | |
--without-mysql-include=${mysql-dir}/include | |
--with-mysql-lib | |
--without-mysql-lib=${mysql-dir}/ | |
--with-mysql-config | |
--without-mysql-config | |
--with-mysql-dir | |
--without-mysql-dir | |
--with-mysql-include | |
--without-mysql-include=${mysql-dir}/include | |
--with-mysql-lib | |
--without-mysql-lib=${mysql-dir}/ | |
--with-mysqlclientlib | |
--without-mysqlclientlib | |
--with-mlib | |
--without-mlib | |
--with-mysqlclientlib | |
--without-mysqlclientlib | |
--with-zlib | |
--without-zlib | |
--with-mysqlclientlib | |
--without-mysqlclientlib | |
--with-socketlib | |
--without-socketlib | |
--with-mysqlclientlib | |
--without-mysqlclientlib | |
--with-nsllib | |
--without-nsllib | |
--with-mysqlclientlib | |
--without-mysqlclientlib | |
--with-mygcclib | |
--without-mygcclib | |
--with-mysqlclientlib | |
--without-mysqlclientlib | |
Gem files will remain installed in /Users/rmswimkkrr/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/mysql2-0.3.15 for inspection. | |
Results logged to /Users/rmswimkkrr/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/mysql2-0.3.15/ext/mysql2/gem_make.out | |
An error occurred while installing mysql2 (0.3.15), and Bundler cannot continue. | |
Make sure that `gem install mysql2 -v '0.3.15'` succeeds before bundling. |
MySQLをインストールしてから再度実行でうまくいきました。(参考)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[xxxxxxxx@yyyyyyyy zzzzz]$bash <(curl -Ls http://git.io/eUx7rg) | |
Downloading MySQL Installers ... may take a few moments | |
######################################################################## 100.0% | |
... | |
... | |
Installing MySQL, administrator password required ... | |
Password: | |
installer: Package name is MySQL 5.6.17-community for Mac OS X | |
installer: Installing at base path / | |
installer: The install was successful. | |
... | |
... | |
Installing MySQL start up items... | |
installer: Package name is MySQL Startup Item | |
installer: Installing at base path / | |
installer: The install was successful. | |
... | |
... | |
Click Install to install the MySQL preferance pane | |
... | |
... | |
... | |
Starting MySQL | |
.. SUCCESS! | |
Setting MySQL root Password to Tke4suoj | |
Placing password on desktop... | |
... | |
... | |
BASE PERFORMANCE MY.CNF IS JUST A GENERIC SUGGESTION FOR PERFORMANCE | |
YOUR RESULTS MAY VARY AND YOU MAY WANT TO FURTHER TUNE YOUR MY.CNF SETTINGS | |
BASE PERFORMANCE MY.CNF INCREASES BUFFERS/MEMORY USAGE | |
8GB+ RAM IS RECOMMENDED FOR BASE PERFORMANCE MY.CNF | |
... | |
DO YOU WANT TO LOAD A BASE PERFORMANCE MY.CNF FILE? [y/N]y | |
Shutting down MySQL | |
.. SUCCESS! | |
Starting MySQL | |
.. SUCCESS! | |
DO YOU WANT TO AUTOMATICALLY INSTALL SEQUEL PRO? [Y/n]n | |
ALL DONE! Install Sequel Pro or phpmyadmin to administer MySQL | |
Log off and log back in for 'mysql' to be recognized as a command in terminal | |
[xxxxxxxx@yyyyyyyy zzzzz]$gem install mysql2 | |
Building native extensions. This could take a while... | |
Successfully installed mysql2-0.3.15 | |
1 gem installed | |
[xxxxxxxx@yyyyyyyy zzzzz]$bundle install | |
Fetching gem metadata from https://rubygems.org/........... | |
Fetching additional metadata from https://rubygems.org/.. | |
Resolving dependencies... | |
Using rake (10.3.1) | |
Using i18n (0.6.9) | |
Using minitest (4.7.5) | |
Using multi_json (1.10.0) | |
Using thread_safe (0.3.3) | |
Using tzinfo (0.3.39) | |
Using activesupport (4.0.4) | |
Using builder (3.1.4) | |
Using erubis (2.7.0) | |
Using rack (1.5.2) | |
Using rack-test (0.6.2) | |
Using actionpack (4.0.4) | |
Using mime-types (1.25.1) | |
Using polyglot (0.3.4) | |
Using treetop (1.4.15) | |
Using mail (2.5.4) | |
Using actionmailer (4.0.4) | |
Using activemodel (4.0.4) | |
Using activerecord-deprecated_finders (1.0.3) | |
Using arel (4.0.2) | |
Using activerecord (4.0.4) | |
Using bundler (1.5.2) | |
Using coffee-script-source (1.7.0) | |
Using execjs (2.0.2) | |
Using coffee-script (2.2.0) | |
Using thor (0.19.1) | |
Using railties (4.0.4) | |
Using coffee-rails (4.0.1) | |
Using hike (1.2.3) | |
Using jbuilder (1.5.3) | |
Using jquery-rails (3.1.0) | |
Using json (1.8.1) | |
Using mysql2 (0.3.15) | |
Using tilt (1.4.1) | |
Using sprockets (2.11.0) | |
Using sprockets-rails (2.0.1) | |
Using rails (4.0.4) | |
Using rdoc (4.1.1) | |
Using sass (3.2.19) | |
Using sass-rails (4.0.3) | |
Using sdoc (0.4.0) | |
Using turbolinks (2.2.2) | |
Using uglifier (2.5.0) | |
Your bundle is complete! | |
Use `bundle show [gemname]` to see where a bundled gem is installed. |
libmysqlclient.18.dylibがないと言われた場合。
参考
2014年5月3日土曜日
プロファイルがHIDの時RN-42とOSX間で通信が途絶える件について
RN-42レポート
秋月で売っている安価なBluetoothモジュールについて記す。
もともとこのモジュールをなぜ手にしたかというと
HHKBを無線化したかったからである。
http://addsict.hatenablog.com/entry/2013/07/27/164647
HHKBは無線版が存在しない。
しかも最近公式から下記のような商品が出た。
http://www.pfu.fujitsu.com/direct/hhkb/detail_enebrick.html
違う…違う…
俺(ら)がほしいのはそれじゃない…。
というわけでGWだし、参考サイト見る限り2日で行けそうと思ったのでやってみたわけだ。
しかし、ここで使ってるBluetoothモジュールRN-42に問題が発生しどうも動かない。
というわけで、悪戦苦闘した結果を伝えたいと思う。
HHKBの無線化は参考サイト通りやるだけで動くようになる(RN-42は秋月の評価版を使用)
http://akizukidenshi.com/catalog/g/gK-07378/
とても素晴らしい。
ただし参考サイトで使っているモジュールはRN-42HIDというもので秋月では手に入らないものになっている。
それとArduinoからRN-42への入力は分圧しているが、
私の環境では分圧しちゃうと信号が届かないので分圧はしなかった。
データシート見る限り分圧しないとモジュールが壊れる気はする。
分圧版
http://secretbase-of-forest.blogspot.jp/2014/04/rn42bluetootharduinoandroid.html
非分圧版
http://benkyo-chu.blogspot.jp/2014/04/rn-42-bluetooth-bluetootharduinoled.html
私の環境で秋月のRN-42評価版を使用した場合に問題が起きるのは、
通信相手としてMBAを選択した場合だけであった。
Windows7とiPhone5では問題が起きず通信が途切れることはないのだが、
MBAとの通信でのみキーボードとの通信が5〜6秒ごとに途絶え、その間のタイプが無視されてしまっていた。
調べてみるとArduinoとHHKBには問題がなく、
RN-42とMBA(OSX 10.9.2)間でのやりとりに問題があるようであった。
このことはRN-42に電源供給のみで他の部品を接続していない状況で
MBAとペアリングを行い、挙動を確認することで判明した。
この組み合わせでも一定間隔でRN-42のLEDが消え、かつBluetoothの接続がMBA側で途切れていることが確認でき、通信→切断→再接続…を繰り返していた。
これはWindows7やiPhone5間ではない挙動であった。
柱上変圧器さんと同じ症状である。[RN-42-EK HID版だが]
(下記コメント欄)
https://www.youtube.com/watch?v=I2gzqrchnlQ
参考サイトの作者に問い合わせを行って見たところ、
やはりRN-42HID版を手に入れてやるのが良いとの助言。
また、OSX 10.9 Marvericksで、途切れる症状は出たことがないとのこと。
参考サイトで同じ症状が出ているもなかさん(下記コメント欄)とも連絡をとってみたところ、
http://addsict.hatenablog.com/entry/2013/08/18/170204
GalaxyNexus(Android)では症状が出ずに、
MBP(OSX)で同じ症状が出ていたとのこと。
RN-42評価版とOSXの組み合わせ(プロファイルはHID)で症状が出るみたい。
取り敢えずもうネット情報でも太刀打ち出来なくなったのでサポートに聞いてみることにする。
誰か何か知ってたら教えて。
参考までにRN-42の設定は下記である。
Mode = Pair
Profile= HID
HidFlags=200
Authen=1
PinCode=1234
秋月で売っている安価なBluetoothモジュールについて記す。
もともとこのモジュールをなぜ手にしたかというと
HHKBを無線化したかったからである。
http://addsict.hatenablog.com/entry/2013/07/27/164647
HHKBは無線版が存在しない。
しかも最近公式から下記のような商品が出た。
http://www.pfu.fujitsu.com/direct/hhkb/detail_enebrick.html
違う…違う…
俺(ら)がほしいのはそれじゃない…。
というわけでGWだし、参考サイト見る限り2日で行けそうと思ったのでやってみたわけだ。
しかし、ここで使ってるBluetoothモジュールRN-42に問題が発生しどうも動かない。
というわけで、悪戦苦闘した結果を伝えたいと思う。
HHKBの無線化は参考サイト通りやるだけで動くようになる(RN-42は秋月の評価版を使用)
http://akizukidenshi.com/catalog/g/gK-07378/
とても素晴らしい。
ただし参考サイトで使っているモジュールはRN-42HIDというもので秋月では手に入らないものになっている。
それとArduinoからRN-42への入力は分圧しているが、
私の環境では分圧しちゃうと信号が届かないので分圧はしなかった。
データシート見る限り分圧しないとモジュールが壊れる気はする。
分圧版
http://secretbase-of-forest.blogspot.jp/2014/04/rn42bluetootharduinoandroid.html
非分圧版
http://benkyo-chu.blogspot.jp/2014/04/rn-42-bluetooth-bluetootharduinoled.html
私の環境で秋月のRN-42評価版を使用した場合に問題が起きるのは、
通信相手としてMBAを選択した場合だけであった。
Windows7とiPhone5では問題が起きず通信が途切れることはないのだが、
MBAとの通信でのみキーボードとの通信が5〜6秒ごとに途絶え、その間のタイプが無視されてしまっていた。
調べてみるとArduinoとHHKBには問題がなく、
RN-42とMBA(OSX 10.9.2)間でのやりとりに問題があるようであった。
このことはRN-42に電源供給のみで他の部品を接続していない状況で
MBAとペアリングを行い、挙動を確認することで判明した。
この組み合わせでも一定間隔でRN-42のLEDが消え、かつBluetoothの接続がMBA側で途切れていることが確認でき、通信→切断→再接続…を繰り返していた。
これはWindows7やiPhone5間ではない挙動であった。
柱上変圧器さんと同じ症状である。[RN-42-EK HID版だが]
(下記コメント欄)
https://www.youtube.com/watch?v=I2gzqrchnlQ
参考サイトの作者に問い合わせを行って見たところ、
やはりRN-42HID版を手に入れてやるのが良いとの助言。
また、OSX 10.9 Marvericksで、途切れる症状は出たことがないとのこと。
参考サイトで同じ症状が出ているもなかさん(下記コメント欄)とも連絡をとってみたところ、
http://addsict.hatenablog.com/entry/2013/08/18/170204
GalaxyNexus(Android)では症状が出ずに、
MBP(OSX)で同じ症状が出ていたとのこと。
RN-42評価版とOSXの組み合わせ(プロファイルはHID)で症状が出るみたい。
取り敢えずもうネット情報でも太刀打ち出来なくなったのでサポートに聞いてみることにする。
誰か何か知ってたら教えて。
参考までにRN-42の設定は下記である。
Mode = Pair
Profile= HID
HidFlags=200
Authen=1
PinCode=1234
登録:
投稿 (Atom)