David Zhang
2011-Jul-04 00:53 UTC
Why does rendered.should have_field pass when it shouldn''t?
This is my new.html.erb_spec.rb: let(:meal) do mock_model("Meal").as_new_record.as_null_object end before(:each) do assign(:meal, meal) end it "shows the name text field" do render rendered.should have_field(:name) # checks for both the label and the text field... right? end it "shows the description text area" do pending "This passes when it shouldn''t" render rendered.should have_field(:description) # have_field is for text fields and text areas (w/labels)... right? end it "shows the ingredients text area" do pending "This passes when it shouldn''t" render rendered.should have_field(:ingredients) end =========This is my new.html.erb: <!--admin/meals#new--> <div id="meal_new"> <h3>New Meal</h3> <%= render :partial => "form", :locals => { :meal => @meal, :button_name => "Create" } %> </div> It renders this partial... =========The partial - _form.html.erb <%= form_for [:admin, meal] do |f| %> <%= f.label :name %> <%= f.text_field :name %> <!---Nothing about f.text_area :description or ingredients here! --> <%= f.submit button_name %> <% end %> ============ The problem: rendered.should have_field(:description) and the one for ingredients are passing although I never specify the description / ingredient text fields or textareas in the form. Why is this? It seems that the presence of the label and text field for :name is enough to make any have_field pass... (have_field DOES test for text fields or text areas, right?) (why does the documentation basically tell you /nothing/? no example or anything.... http://rubydoc.info/github/jnicklas/capybara/master/Capybara/RSpecMatchers#have_field-instance_method) Help would be greatly appreciated. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/BqpTVkUheasJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
David Zhang
2011-Jul-05 23:19 UTC
Re: Why does rendered.should have_field pass when it shouldn''t?
Maybe this question is a little to wordy, so I''ll just ask this: Could someone just tell me if '''''''' it "shows the name text field" do render rendered.should have_field(:name) end '''''''' ...checks for both the label and the text field? How come when I have ONE text field in my view, all such have_field(:blahs) pass? They shouldn''t! I must be missing something... -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/joZIXagh6dUJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.