On 3 August 2011 21:37, David Chelimsky <[email protected]> wrote:
> >> Keep in mind that rspec-rails is a thin wrapper around the built-in > Rails testing framework. The convention of relating a symbol in the spec to > an instance variable in the view was established by Rails with the `assigns` > method in functional tests (controller specs in rspec): > >> > >> thing = Factory(:thing) > >> get :index > >> assigns(:thing).should eq(thing) > >> > >> In the last line, `assigns(:thing)` refers to the `@thing` instance > variable in the view. > >> > >> HTH, > >> David > > > > Hello David > > Thanks for that. Doesn't assign have 2 arguments with the first being the > variable to be assigned to and the second being the contents? > > Yes, `assign`, in view specs, has two arguments. `assigns` (plural), in > controller specs (and provided by Rails) takes only one. `assign` is a > setter for a single instance variable, `assigns` is a getter which keys into > a map of all assigned instance variables. > Thanks for the reply and the link <http://idallen.com/topposting.html> for posting. I learnt something. Back to the question, I revisited the spec I was working on and made the following comments (see the arrows). describe "parts/new.html.erb" do let(:part) { <----- the mocked model mocking operation is assigned to a method with the symbol of :part. I think it's because the mocked model is to be assigned to the @part instance variable in the view (also refered to as :part in the current spec's scope). Am I right? mock_model('Part').as_new_record.as_null_object } before do assign(:part, part) <---- :part refers to the part var in spec (@part in view), whilst 'part' at the end refers to just the part method in let.. Am I right? If that's the case, it makes little sense to call a method name the same name as the instance variable (ie. 'part' let method similar to the @part instance view variable)? end it "renders a form to add a new part" do render render.should have_selector( "form", :method => "post", :action => parts_path, ) do |form| form.should have_selector("input", :type => "submit") end end it "renders input fields to add a new part" do part.stub("title"=> "HKS EVC boost controller") render rendered.should have_selector( "form" ) do |form| form.should have_selector( "input", :type => "text", :name => "part[title]", :value => "HKS EVC boost controller" ) end end end Thank you, David and potentially, everyone :) -- You received this message because you are subscribed to the Google Groups "rspec" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rspec?hl=en.
