Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

2014-04-01から1ヶ月間の記事一覧

RSpec | rspec command | pattern option

概要 rspec command | pattern option 詳細 rspec commandのpattern optionでワイルドカードなどを利用したパターン文字列で テスト対象を抽出して実行できます。 デフォルトは「spec/**/*_spec.rb」になっています。 構成 $ tree ┣ lib | ┣ hage.rb | ┣ h…

Ruby | Integer | gcdlcm

概要 Integer#gcdlcm 詳細 最大公約数と最小公倍数の配列を取得します。 gcd = Greatest Common Divisor lcm = Least Common Multiple サンプルコード # encoding: utf-8 require 'tbpgr_utils' bulk_puts_eval binding, <<-EOS 2.gcdlcm 4 2.gcdlcm -4 2.gc…

Ruby | 二次元配列の各先頭の任意のindexに値を追加する

概要 二次元配列の各先頭の任意のindexに値を追加する 詳細 tbpgr_utils gemのArray#together_insert(別名でtinsertもあり) 二次元配列の各先頭の任意のindexに値を追加します。index指定を負の数にすると、Array#insertと同様に後ろから数えた位置に挿入…

Ruby | 二次元配列の各先頭の値のindexを取得する

概要 二次元配列の各先頭の値のindexを取得する 詳細 tbpgr_utils gemのArray#together_index(別名でtindexもあり) 二次元配列の各先頭の値のindexを取得します。 事前準備 gem install tbpgr_utils 主な用途 二次元配列の各先頭の値のindexを取得したい場…

TbpgrUtils | 追加要件 Numeric to_oct_html_table 追加

概要 追加要件 Numeric to_oct_html_table 追加 詳細 追加要件 Numeric to_oct_html_table 仕様 ・10/16進数をHTMLの表形式の文字列で取得します ※より詳細についてはGitHubのREADMEおよびテストケース参照 GitHub https://github.com/tbpgr/tbpgr_utils Rub…

RSpec | rspec command | tag option

概要 rspec command | tag option 詳細 rspec commandのtag optionで行数指定で実行します。 サンプルテストコード(hige_spec.rb) # encoding: utf-8 require "spec_helper" require "hige" describe Hige do it "hige1 1", :hige1 => "hige", hige: true do…

RSpec | rspec command | line_number option

概要 rspec command | line_number option 詳細 rspec commandのline_number optionで行数指定で実行します。 サンプルテストコード(hoge_spec.rb) # encoding: utf-8 require "spec_helper" require "hoge" describe Hige do it "hoge1 1" do # some spec e…

RSpec | rspec command | init option

概要 rspec command | init option 詳細 rspec commandのinit optionで 前提 RSpec 2.14.7で動作確認 動作確認 rspec --init か rspec -i コマンドで 「.rspec」「spec」「spec/spec_helper.rb」を生成してくれます。 $rspec -i create spec/spec_helper.rb …

RSpec | rspec command | format option

概要 rspec command | format option 詳細 rspec commandのformat optionで出力フォーマットを制御できます。 サンプルテストコード(hoge_spec.rb) # encoding: utf-8 require "spec_helper" require "hoge" describe Hige do it "hoge1 1" do # some spec e…

RSpec | rspec command | fail fast option

概要 rspec command | fail fast option 詳細 rspec commandのfail fast optionでテスト失敗時に即実行を終了できます。 rspec --fail-fast サンプルコード(hoge.rb) 100メソッド定義 # encoding: utf-8 class Hoge (1..100).each do |i| define_method "hog…

RSpec | rspec command | exit status

概要 rspec command | exit status 詳細 rspec commandによるテスト実行時に 全テストが成功ならexit statusは0 そうでなければexit statusは1 になります。 サンプルコード1(hoge_spec.rb) # encoding: utf-8 require "spec_helper" require "hoge" descr…

RSpec | rspec command | example option とRSpecPiccoloの組み合わせ

概要 example option とRSpecPiccoloの組み合わせ 詳細 example option とRSpecPiccoloの組み合わせについて。 RSpecPiccoloは私が自作したgemで、パラメタライズドテストに利用します。https://rubygems.org/gems/rspec_piccolo https://github.com/tbpgr/r…

RSpec | rspec command | example option

概要 rspec command | example option 詳細 rspec commandのexample optionで ・特定の一つのexampleのみ実行 ・特定の名前に一致するexampleを全て実行 ・example optionを複数回指定して複雑な条件で任意のテストを実行する などのようなことができます。 …

Ruby | Integer | gcd

概要 Integer#gcd 詳細 最大公約数を取得します。 gcd = the Greatest Common Divisor サンプルコード # encoding: utf-8 require 'tbpgr_utils' bulk_puts_eval binding, <<-EOS 2.gcd 4 2.gcd -4 2.gcd 0 0.gcd 2 12.gcd 24 EOS __END__ 下記はTbpgrUtils …

CodeIQ 第2回デスマコロシアム解答チェック用 Greasemonkeyユーザースクリプト の公開

概要 CodeIQ 第2回デスマコロシアム解答チェック用 Greasemonkeyユーザースクリプト の公開 詳細 CodeIQ 第2回デスマコロシアム解答チェック用 Greasemonkeyユーザースクリプトを下記に置いておきました。https://github.com/tbpgr/codeiq_q835_checker設定…

Ruby | 指定した値が二次元配列に含まれているか確認する

概要 指定した値が二次元配列に含まれているか確認する 詳細 tbpgr_utils gemのArray#together_include?(別名でtinclude?もあり) 指定した値が二次元配列に含まれているか確認します。 デフォルトでは、複数ある配列のどれか1つに含まれていればtrueを返却…

Ruby | 二次元配列の各先頭要素を取得する

概要 二次元配列の各先頭要素を取得する 詳細 tbpgr_utils gemのArray#together_first(別名でtfirstもあり) 二次元配列の各先頭要素を取得します。 事前準備 gem install tbpgr_utils 主な用途 二次元配列の各先頭要素を取得したいとき。 サンプルコード #…

TbpgrUtils | 追加要件 Numeric to_hex_html_table 追加

概要 追加要件 Numeric to_hex_html_table 追加 詳細 追加要件 Numeric to_hex_html_table 仕様 ・10/16進数をHTMLの表形式の文字列で取得します ※より詳細についてはGitHubのREADMEおよびテストケース参照 GitHub https://github.com/tbpgr/tbpgr_utils Rub…

RSpec | rspec-core shared examples

概要 rspec-core shared examples 詳細 shared examplesは複数のexample間で共有するexampleを定義できます。 include_examplesで呼び出します。 alias main alias shared_examples shared_context shared_examples shared_examples_for include_examples in…

RSpec | rspec-core metadata

概要 rspec-core shared metadata 詳細 metadata RSpecのexample.metadataはメタデータをハッシュで保持している。 described_class described_classでdescribeのクラスを取得可能。 shared_examlesなどを作成する際に、 処理対象のクラス名称を問わずに利用…

RSpec | rspec-core describe/context/it/example/specify

概要 rspec-core describe/context/it/example/specify 詳細 describe describeはExampleGroupを生成します。 it describeの内側で、itメソッドを利用してexampleを作成できます。 alias main alias memo describe context トップレベルではdescribeのみ利用…

Ruby | Integer | even?

概要 Integer#even? 詳細 数値が偶数か判定します。 サンプルコード # encoding: utf-8 (1..10).each { |v| puts "#{v} is even? :#{v.even?} " } 出力 1 is even? :false 2 is even? :true 3 is even? :false 4 is even? :true 5 is even? :false 6 is even…

Ruby | 二次元配列の各要素全てに同じ値を設定する

概要 二次元配列の各要素全てに同じ値を設定する 詳細 tbpgr_utils gemのArray#together_fill。(別名でtfillもあり) 二次元配列の各要素全てに同じ値を設定します。 事前準備 gem install tbpgr_utils 主な用途 二次元配列の要素を全て同じ値にしたい場合…

Ruby | 二次元配列の各要素全てが空かどうか検証する

概要 二次元配列の各要素全てが空かどうか検証する 詳細 tbpgr_utils gemのArray#together_empty?。(別名でtempty?もあり) 二次元配列の各要素全てが空かどうか検証します。 事前準備 gem install tbpgr_utils 主な用途 二次元配列の各要素全てが空かどう…

TbpgrUtils | 追加要件 Numeric to_digit_html_table 追加

概要 追加要件 Numeric to_digit_html_table 追加 詳細 追加要件 Numeric to_digit_html_table 仕様 ・10/2/8/16進数をHTMLの表形式の文字列で取得します ※より詳細についてはGitHubのREADMEおよびテストケース参照 GitHub https://github.com/tbpgr/tbpgr_u…

Ruby | Ruby2.1新規要素 | String#scrub

概要 String#scrub 詳細 不正なバイト列を任意の文字に置換します サンプルコード # encoding: utf-8 # A 不正バイト a をstrに格納 str = "\x41\xff\x61" str.force_encoding('UTF-8') str = str.scrub('@') print str 出力 A@a

Ruby | Ruby2.1新規要素 | defの戻り値変更

概要 defの戻り値変更 詳細 defの戻り値が変更され、メソッド名のシンボルを返却するようになった。 (※以前はnilを返却していた)この変更は private def hoge # some code end のような記述を可能にしたい、というのが出発点のようです。 下記が、Rubyのコ…

Ruby | Integer | downto

概要 Integer#downto 詳細 ブロック指定した場合は、selfからdowntoの引数へ値を減らしながら ブロック内の処理を繰り返します。ブロック指定しない場合は、Enumratorを返却します。 サンプルコード # encoding: utf-8 5.downto(1) { |v| print "#{v}, " } p…

Ruby | 二次元配列の各要素のうち、ブロックで指定した条件に一致する要素を削除する

概要 二次元配列の各要素のうち、ブロックで指定した条件に一致する要素を削除する 詳細 tbpgr_utils gemのArray#together_delete_if。(別名でtdelete_ifもあり) 二次元配列の各要素のうち、ブロックで指定した条件に一致する要素を削除します 事前準備 ge…

Ruby | 二次元配列の各要素から指定インデックスの要素を削除する

概要 二次元配列の各要素から指定インデックスの要素を削除する 詳細 tbpgr_utils gemのArray#together_delete_at。(別名でtdelete_atもあり) 二次元配列の各要素から指定インデックスの要素を削除します 事前準備 gem install tbpgr_utils 主な用途 二次…