나는 정말로 유닛 테스트를 처음 접했고 그 주위를 감싸하려고 노력 중이다. 따라서 사용자가 title
과 description
을 입력하고 Create Article
을 클릭하면 기사 양식을 작성해야하지만 상황은 로그인 한 사용자 만이 작업을 수행 할 수 있으므로 테스트해야합니다. Ruby on Rails - 테스트 케이스에 사용자 추가하기
나는이 새로운 오전부터
은 그래서 이것은 내가 생각하고 무엇 방법 시스템 검사를 먹으 렴으로 사용자가 로그인하면 내가 세션에 저장을 먼저 사용자-
(하지만 그런 다음이 논리가 작동하지 않을 수도있는 브라우저가 아니라고 생각합니다.) 그러면 로그인 한 사용자로 양식을 제출하는 방법은 무엇입니까? 내가
이
Failures:
1) adding article allow user to add an article Failure/Error: session[:user_id] = @user.id
NameError: undefined local variable or method `session' for #<RSpec::ExampleGroups::AddingArticle:0x007f89285e32e8> # ./spec/features/add_article_spec.rb:6:in `block (2 levels) in <top (required)>'
Finished in 0.0197 seconds (files took 1.35 seconds to load) 1 example, 1 failure
Failed examples:
rspec ./spec/features/add_article_spec.rb:4 # adding article allow user to add an article
그래서 내 질문에 내가이 로그인으로 기사를 어떻게 추가합니까 것을 볼 rspec spec/features/add_article_spec.rb
명령을 실행하면 여기
require 'rails_helper'
RSpec.feature 'adding article' do
scenario 'allow user to add an article' do
@user = User.create(:email => "[email protected]", :password => 'password', :username => 'saadia1')
session[:user_id] = @user.id
visit new_article_path
# @article = Article.user.to eql(@user = User.find_by(id: 6))
fill_in "Title", with: "My Title"
fill_in "Description", with: "My description"
click_on("Create Article")
expect(page).to have_content("My Title")
expect(page).to have_content("My description")
end
end
입니다 사용자? 나는 이것에 대한 도움을 정말로받을 것이다.
감사합니다. 예, 사용하고 있습니다. 나는 다시하려고 노력할 것이다. – Saadia