16
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RSpec小ネタ的メモ

Posted at

##レシーバの省略

Memberがモデル。
この場合、subjectで指定しなくてもshouldのレシーバはMember.newしたインスタンスとなる。


decribe Member do
 it { should_not be_nil }
end

##be_a_newマッチャ

対象が指定したクラスのインスタンスかつ未保存レコードであることを検証する。

decribe Member do
 it { should be_a_new(Member) }
end

##have_at_least(n).errors(attr)マッチャ

指定した属性のエラーの数を検証。
have_at_least以外にもhaveとかが使える。

decribe Member do
 it { should have_at_least(1).errors_on("name") }
end

##レスポンスの検証

be_success
be_redirect
be_client_error
be_server_error

##レスポンスヘッダの検証

response['hogehoge'].should =~ %r(hogehoge)
16
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?