2012-02-08 14 views
7

असफल संसाधन 1.3.0 के साथ एक परियोजना के लिए रेल 3.1.3 का उपयोग कर रहा हूं।रेल 3.1.3 और विरासत संसाधन परीक्षण

जब मैं तो जैसे एक नियंत्रक है:

class PostsController < InheritedResources::Base 
end 

और मैं निम्नलिखित

describe "PUT update" do 
    describe "with invalid params" do 
     it "re-renders the 'edit' template" do 
     post = Post.create! valid_attributes 
     # Trigger the behavior that occurs when invalid params are submitted 
     Post.any_instance.stub(:save).and_return(false) 
     put :update, {:id => post.to_param, :post => {}}, valid_session 
     response.should render_template("edit") 
     end 
    end 
    end 

मैं निम्नलिखित त्रुटि मिलती है rspec साथ परीक्षण:

3) PostsController PUT update with invalid params re-renders the 'edit' template 
    Failure/Error: response.should render_template("edit") 
     expecting <"edit"> but rendering with <""> 
    # ./spec/controllers/posts_controller_spec.rb:115:in `block (4 levels) in <top (required)>' 

ऐसा क्यों है? क्या मुझे कुछ और करना है?

उत्तर

13

बस इस जोड़ें:

Post.any_instance.stub(:errors).and_return(['error']) 

सही होने के बाद:

Post.any_instance.stub(:save).and_return(false) 
संबंधित मुद्दे