Tbpgr Blog

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

書籍 RSpec Book | Hello RSpec

概要

Hello RSpec

内容

RSpecHello Worldします。
RSpecのテストは規約として「*_spec.rb」とする必要があります。

テストコード

hello_hoge_spec.rb

# encoding: utf-8
require_relative "../open_classes.rb"
require_relative "./2_1"

describe "Hello Hoge" do
  it "hoge_hoge()を呼び出した時、'Hello Hoge!'と表示されること" do
    hoge = HelloHoge.new
    hello_hoge = hoge.hello_hoge
    hello_hoge.should == "Hello Hoge!"
  end
end

hello_hoge.rb

# encoding: utf-8
require_relative "../open_classes.rb"

class HelloHoge
  def hello_hoge
    "Hello Hoge!"
  end
end

テスト結果

$rspec hello_hoge_spec.rb
.

Finished in 0.006 seconds
1 example, 0 failures