LoginSignup
1
0

More than 5 years have passed since last update.

Rspecで使うletメモ

Posted at

参照:https://qiita.com/jnchito/items/42193d066bd61c740612
スーパーわかりやすいでごわす

letの基本

変数っぽく使えるのが便利

feature 'hogee' do
  let(:user) { create(:user) }

  scenario 'hogehoge' do
    # ~省略~
  end

end

今回の場合であれば、feature 'hogee' doからendまでusercreate(:user)として使える

よって、

feature 'tweet', type: :feature do
  let(:user) { create(:user) }

  scenario 'post tweet' do
    # ログイン処理
    visit new_user_session_path
    fill_in 'user_email', with: user.email
    fill_in 'user_password', with: user.password
    find('input[name="commit"]').click
    expect(current_path).to eq root_path
    expect(page).to have_content('投稿する')
  end
end

こんなこともできる

1
0
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
1
0