을 쓰는 더 좋은 방법이 있어야합니다. 로그인하지 않은 사용자, Consumer, Producer 및 Admin의 4 가지 사용자 클래스가 있습니다.Rspec, 내 시스템에
현재 Cancan for ACL을 사용하고 있습니다. 심지어 관리자 섹션에서 작성되지 않은하지만이이 일에 대해 갈 수있는 권장 방법이 아니다 꽤 확신
describe DealsController do
describe "non-signed-in users" do
before(:each) do
@deal = Factory(:deal)
end
describe "should be able to" do
it "access index" do get :index end
it "show deal" do get :show, :id => @deal end
after(:each) do
response.should be_success
end
end
describe "should not be able to" do
it "redeem" do get :redeem end
it "new" do get :new end
it "edit" do get :edit, :id => @deal end
it "update" do get :update, :id => @deal end
it "destroy" do get :destroy, :id => @deal end
after(:each) do
response.should_not be_success
response.should redirect_to(root_path)
flash[:error].should == "Permission denied."
end
end
end
describe "consumers" do
before(:each) do
@user = test_sign_in(Factory(:user, :role => "consumer"))
@deal = Factory(:deal)
end
describe "should be able to" do
it "access index" do get :index end
it "show deal" do get :show, :id => @deal end
after(:each) do
response.should be_success
end
end
describe "should not be able to" do
it "redeem" do get :redeem end
it "new" do get :new end
...
after(:each) do
response.should_not be_success
response.should redirect_to(root_path)
flash[:error].should == "Permission denied."
end
end
end
describe "producer" do
before(:each) do
@user = test_sign_in(Factory(:user, :role => "producer"))
@business = Factory(:business, :user_id => @user.id)
@deal = Factory(:deal, :business_id => @business.id)
end
it "should be able to access index" do
get :index
response.should be_success
end
describe "in show deals" do
it "should be able to see merchant controls for his deal" do
get :show, :id => @deal
response.should have_selector('h3', :content => "Merchant Controls")
end
it "should not be able to see merchant controls for other's deal" do
@user2 = Factory(:user, :role => "producer")
@business2 = Factory(:business, :user_id => @user2.id)
@deal2 = Factory(:deal, :business_id => @business2.id)
get :show, :id => @deal2
response.should_not have_selector('h3', :content => "Merchant Controls")
end
end
describe "should not be able to" do
it "new" do get :new end
...
after(:each) do
response.should_not be_success
response.should redirect_to(root_path)
flash[:error].should == "Permission denied."
end
end
end
end
: RSpec에를 쓰는 동안
, 나는 다음과 같은보고하고있다.
더 좋은 방법이 있습니까?
감사합니다. 나는 rspec과 테스트에 익숙하지 않으며 이것은 정말로 도움이된다. – disappearedng
FWIW와 나는 이것이 나에게 일어날지도 모른다는 것을 이해한다. 그러나 나는 한 라이너가 {...} 대 V ... 할 일을하는 것을 발견한다. 나는 그 후에 괄호로 설명해야만한다. 즉, Rspec 2.13, ruby 2에 있으며 테스트를 위해 dRb와 함께 spork 및 guard를 사용하고 있습니다. 좋은 대답! 내가 한번 이상 upvote 수 있기를 빌어! :) – engineerDave