RSpec Ruby学習ログ

subject, itの組み合わせ。

describe "subject and it" do
  subject{ [1, 2, 3, 3] }
  it { should == [1, 2, 3, 3] }
  it { should include 1 }
  it { should have(4).items }
  it { should_not =~ [1, 2, 3, 4] }
  it { should satisfy{ |subj| subj.first == 1 } }
  it { subject.first.should == 1 }
end

satisfyの実行結果レポートは長すぎ
subject.firstの実行レポートは短すぎるか。

subjectの記述部分をdescribeに書ける

describe [1, 2, 3, 3] do
  it { should == [1, 2, 3, 3]}
  it { should include 1}
  it { should have(4).items }
  it { should have_at_least(3).items }
  it { should_not =~ [1, 2, 3, 4]}
  it { should satisfy{ |subj| subj.first == 1} }
  it { subject.first.should == 1 }
end