RubyでTDDをしてみる
1.Cucumberで1つのシナリオに焦点を合わせる
#
language:
ja
機能:
文字列の表示
シナリオ:
sample.rbを実行する
#
features/sample.feature:4
もしsample.rbを実行した場合
#
features/sample.feature:5
かつメッセージが出力される
#
features/sample.feature:6
ならば"Hiroshima.rb
#027"と表示している
#
features/sample.feature:7
1
scenario
(1
undefined)
3
steps
(3
undefined)
0m0.003s Step definitions
You
can
implement
step
definitions
for
undefined
steps
with
these
snippets: に書いてね
もし
/^sample.rbを実行した場合$/
do
pending
#
express
the
regexp
above
with
the
code
you
wish
you
had
end
もし
/^メッセージが出力される$/
do
pending
#
express
the
regexp
above
with
the
code
you
wish
you
had
end
ならば
/^"(.*?)"と表示している$/
do
|arg1|
pending
#
express
the
regexp
above
with
the
code
you
wish
you
had
end
13年2月2日土曜日 16
17.
RubyでTDDをしてみる
2.失敗するステップ定義を書く
# coding: utf-8
もし /^sample.rbを実行した場合$/ do
pending # express the regexp above with the code you wish you had
end
もし /^メッセージが出力される$/ do
pending # express the regexp above with the code you wish you had
end
ならば /^"(.*?)"と表示している$/ do |arg1|
pending # express the regexp above with the code you wish you had
end
13年2月2日土曜日 17
RubyでTDDをしてみる
2.失敗するステップ定義を書く
# coding: utf-8
もし /^sample.rbを実行した場合$/ do
@sample = Sample.new
end
もし /^メッセージが出力される$/ do
@message = @sample.message
end
ならば /^"(.*?)"と表示している$/ do |arg1|
@message.should == 'Hiroshima.rb #027'
end
13年2月2日土曜日 19
20.
RubyでTDDをしてみる
3.Rspecで失敗するサンプルを書く
require 'sample'
describe "Message" do
it "get message" do
sample = Sample.new
message = sample.message
message.should == 'Hiroshima.rb #027'
end
end
13年2月2日土曜日 20
21.
RubyでTDDをしてみる
3.Rspecで失敗するサンプルを書く
F “F”が失敗したということ
Failures:
1) Message get message
Failure/Error: sample = Sample.new
NameError:
uninitialized constant Sample
# ./spec/sample_spec.rb:5:in `block (2 levels) in <top (required)>'
Finished in 0.00077 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/sample_spec.rb:4 # Message get message
13年2月2日土曜日 21