테스트를 사양에 추가함에 따라 필자가 작성한 모든 단일 테스트가 의심스러워졌습니다. 구문 오류를 코드에 추가합니다. 결과적으로 Rspec이 최근 테스트를 실행하지 않아서 구문 오류가 발생하지 않았습니다. 아래 코드의 주석이 RSpec에 테스트를위한 녹색 기간 또는 빨간색 F 보여주는 정지되는 임의의 라인을 보여줍니다 나는 의도적으로 이전 테스트 구문 오류를 추가 할 때Rspec with Guard 및 Spork는 일부 테스트를 실행하지 않고 오류에 대한 자세한 오류 문을 표시하지 않습니다.
require 'spec_helper'
describe Api::PagesController do
def valid_session
{}
end
describe "GET index" do
before :each do
@page = create(:page)
end
it "assigns all pages as @pages" do
get :index
assigns(:pages).should eq([@page])
end
it "returns json" do
get :index, format: :json
expect(response.body).to have_content @page.to_json
end
end
describe "GET show" do
before :each do
@page = create(:page)
end
it "assigns the requested page as @page" do
get :show, {:id => @page.to_param}, valid_session
assigns(:page).should eq(@page)
end
it "returns json" do
get :show, {:id => @page.to_param}, valid_session, format: :json
expect(response.body).to have_content @page.to_json
end
end
describe "GET new" do
it "assigns a new page as @page" do
get :new, {}, valid_session
assigns(:page).should be_a_new(Page)
end
end
describe "GET edit" do
before :each do
@page = create(:page)
end
it "assigns the requested page as @page" do
get :edit, {:id => @page.to_param}, valid_session
assigns(:page).should eq(@page)
end
it "returns json" do
get :edit, {:id => @page.to_param}, valid_session, format: :json
expect(response.body).to have_content @page.to_json
end
end
describe "POST create" do
describe "with valid params" do
it "creates a new Page in the database" do
expect {
post :create, {page: attributes_for(:page)}, valid_session
}.to change(Page, :count).by(1)
end
it "assigns a newly created page as @page" do
post :create, {page: attributes_for(:page)}, valid_session
assigns(:page).should be_a(Page)
assigns(:page).should be_persisted
end
#################### TESTS BELOW HERE ARE NOT SHOWN BY RSPEC##########
it "returns json" do
expect{
post :create, {page: attributes_for(:page)}, valid_session
}.to have_content page.to_json
end
end
describe "with invalid params" do
it "does not save the new page in the database" do
expect {
post :create, {page: attributes_for(:page_invalid)}, valid_session
}.to_not change(Page, :count).by(1)
end
#FUTURE TEST - redirects to new page with errors
end
end
describe "PUT update" do
before :each do
@page = create(:page)
end
describe "with valid params" do
it "updates the requested page" do
Page.any_instance.should_receive(:update_attributes).with({ "title" => "MyString" })
put :update, {:id => @page.to_param, :page => { "title" => "MyString" }}, valid_session
end
it "assigns the requested page as @page" do
put :update, {:id => @page.to_param, :page => { "title" => "MyString" }}, valid_session
assigns(:page).should eq(@page)
end
it "returns json" do
put :update, {:id => @page.to_param, :page => { "title" => "MyString" }}, valid_session, format: :jason
expect(response.body).to have_content @page.to_json
end
end
describe "with invalid params" do
it "assigns the page as @page" do
# Trigger the behavior that occurs when invalid params are submitted
Page.any_instance.stub(:save).and_return(false)
put :update, {:id => @page.to_param, page: attributes_for(:page_invalid)}, valid_session
assigns(:page).should eq(@page)
end
#FUTURE TEST - redirects to edit
end
end
describe "DELETE destroy" do
before :each do
@page = create(:page)
end
it "destroys the requested page" do
expect {
delete :destroy, {:id => @page.to_param}, valid_session
}.to change(Page, :count).by(-1)
end
end
describe "GET published" do
before :each do
@page = create(:page)
@page_unpublished = create(:page_unpublished)
end
it "returns a list of published pages only" do
get :published, format: :json
assigns(:pages).should eq([@page])
expect(response.body).to have_content @page_unpublished.to_json
end
end
describe "GET unpublished" do
before :each do
@page = create(:page)
@page_unpublished = create(:page_unpublished)
end
it "returns a list of unpublished pages only" do
get :unpublished, format: :json
assigns(:pages).should eq([@page_unpublished])
expect(response.body).to have_content @page_unpublished.to_json
end
end
describe "GET total_words" do
before :each do
@page = create(:page)
end
it "returns a list of unpublished pages only" do
get :total_words, {:id => @page.to_param}, format: :json
assigns(:total_words).should eq([@page_unpublished])
expect(response.body).to have_content @page_unpublished.to_json
end
end
end
을, 나는 녹색의 빨간색 대신 F는 보았다 점이 있지만 오류는보고되지 않았습니다. 오류가있을 때 이전, I (예를 들어) 볼 것 : 테스트가 실패 할 때 이제
16:10:14 - INFO - Running: spec/models/page_spec.rb
Running tests with args ["--drb", "-f", "progress", "-r", "/Users/user/.rvm/gems/ruby-1.9.3-p194/gems/guard-rspec-1.2.1/lib/guard/rspec/formatters/notification_rspec.rb", "-f", "Guard::RSpec::Formatter::NotificationRSpec", "--out", "/dev/null", "--failure-exit-code", "2", "spec/models/page_spec.rb"]...
.......F
Failures:
1) Page Publishing returns unpublished pages
Failure/Error: expect(Page.unpublished).to eq [page_unpublished]
NameError:
undefined local variable or method `page_unpublished' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_4:0x0000010355b8c0>
# ./spec/models/page_spec.rb:58:in `block (3 levels) in <top (required)>'
Finished in 0.54212 seconds
8 examples, 1 failure
Failed examples:
rspec ./spec/models/page_spec.rb:57 # Page Publishing returns unpublished pages
Done.
를, 나는 단지 참조 :
17:55:26 - INFO - Running: spec/controllers/pages_controller_spec.rb
Running tests with args ["--drb", "-f", "progress", "-r", "/Users/user/.rvm/gems/ruby-1.9.3-p194/gems/guard-rspec-1.2.1/lib/guard/rspec/formatters/notification_rspec.rb", "-f", "Guard::RSpec::Formatter::NotificationRSpec", "--out", "/dev/null", "--failure-exit-code", "2", "spec/controllers/pages_controller_spec.rb"]...
.....FF..Done.
이 변경 꽤 임의의 시간에 무슨 일이 있었 코딩 중 GuardFile 또는 Spork 구성 세부 정보는 수정하지 않았습니다. 왜 이런 일이 일어나는 지 아십니까?
네,하지만이 플래그는 rspec이 올바른 답을 줄 때 설정되었습니다. 그래도 국기를 어떻게 바꿀 수 있습니까? –
죄송합니다. 방금 다른 형식 옵션이있는 것으로 나타났습니다. --out은 NotificationRSpec 인 마지막 형식 옵션에만 적용됩니다. 그래서 그렇지 않습니다. –
여하튼, 문제를 반복 할 수 있는지 알아보기 위해 경비원과 spork을 종료하고 rspec을 다시 실행 해 보셨습니까? 그걸 없애면 환경의 변화를 다시 불러 오기 위해 spork과 guard를 다시 시작해야 할 수도 있습니다. –