嘗試通過ajax創建rspec測試以獲取方法。重試302狀態,但期望200. Post方法的測試返回相同的結果。 user_pages_spec.rb嘗試通過ajax創建rspec測試以獲取方法
require 'spec_helper'
describe "ProgectPage" do
subject { page }
let(:user) { FactoryGirl.create(:user) }
before(:each) do
visit signin_path
fill_in "Email", with: user.email.upcase
fill_in "Password", with: user.password
click_button "Sign in"
end
describe "createProgect" do
describe "vith invalid data" do
before do
click_link "Add TODO list"
fill_in "progect_title", with: 'Progect new'
fill_in "progect_date_end", with: ''
click_button "Save"
end
it { should have_selector('div.alert.alert-error') }
end
describe "vith valid data" do
before do
click_link "Add TODO list"
fill_in "progect_title", with: 'Progect new'
fill_in "progect_date_end", with: '2014-10-10'
end
it "should increment the progect count" do
expect do
click_button "Save"
end.to change(user.progects, :count).by(1)
end
end
end
it "has a 200 status code" do
#p user.inspect
xhr :get, '/users/1'
# p response.inspect
response.code.should == "200"
end
# it "has a 200 status code" do
# xhr :post, '/progects', progect: {title: "First Progect", date_end: "2014-10-11", user_id: 1}
# p response.inspect
# response.code.should == "200"
# end
end
耙路由
Prefix Verb URI Pattern Controller#Action
duties_new GET /duties/new(.:format) duties#new
users_new GET /users/new(.:format) users#new
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
sessions POST /sessions(.:format) sessions#create
new_session GET /sessions/new(.:format) sessions#new
session DELETE /sessions/:id(.:format) sessions#destroy
progects POST /progects(.:format) progects#create
progect DELETE /progects/:id(.:format) progects#destroy
duties POST /duties(.:format) duties#create
duty DELETE /duties/:id(.:format) duties#destroy
root GET / sessions#new
signin GET /signin(.:format) sessions#new
signout DELETE /signout(.:format) sessions#destroy
PUT /duties/:id(.:format) duties#update
duties_updpos POST /duties/updpos(.:format) duties#updpos
PUT /progects/:id(.:format) progects#update
束EXEC rspec的規格/請求/ user_pages_spec.rb
F..
Failures:
1) ProgectPage has a 200 status code
Failure/Error: response.code.should == "200"
expected: "200"
got: "302" (using ==)
# ./spec/requests/user_pages_spec.rb:45:in `block (2 levels) in <top (required)>'
Finished in 0.6253 seconds
3 examples, 1 failure
Failed examples:
rspec ./spec/requests/user_pages_spec.rb:41 # ProgectPage has a 200 status code
UPD
it "has a 200 status code" do
xhr :get, :show, id: 1
response.code.should == "200"
end
有錯誤
F..
Failures:
1) ProgectPage has a 200 status code
Failure/Error: xhr :get, :show, id: 1
ArgumentError:
bad argument (expected URI object or URI string)
# ./spec/requests/user_pages_spec.rb:44:in `block (2 levels) in <top (required)>'
Finished in 0.6102 seconds
3 examples, 1 failure
Failed examples:
rspec ./spec/requests/user_pages_spec.rb:41 # ProgectPage has a 200 status code
Randomized with seed 13402