|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
Need help in View SpecHello everyone:
I am kind of puzzled in writing spec on view partials. I can not find much information about the "should have_tag" syntax in Rspec. Can rspec test a particular attribute of a tag (e.g. input tag)? Let me put an example here: #../view/group/_index <div id="test"> <input type="button" value="update" onclick="update()" /> </div> I want to test the "onclick" attribute in the input tag, which ensure that clicking the button will call the correct Javascript method. How should I do? Great thanks for any help. |
|
|
Re: Need help in View SpecOn 9/13/07, Shaker <flyeminent@...> wrote:
> I can not find much > information about the "should have_tag" syntax in Rspec. http://rspec.rubyforge.org/rdoc-rails/classes/Spec/Rails/Matchers.html#M000011 _______________________________________________ rspec-users mailing list rspec-users@... http://rubyforge.org/mailman/listinfo/rspec-users |
|
|
Re: Need help in View SpecYes, I have gone through the documentation before, and I read the reference of 'assert_select' as well. But I still can not figure out a way of testing attributes in a tag. What I know is we can use:
should have_tag("tag#id") or should have_tag("tag.class") to select a tag, whereas I don't know how to select an attribute and test it! Another problem is the tag does not have id or class sometimes, does it mean that is no way of selecting it?
|
|
|
Re: Need help in View SpecOn 9/13/07, Shaker <flyeminent@...> wrote:
> > Yes, I have gone through the documentation before, and I read the reference > of 'assert_select' as well. But I still can not figure out a way of testing > attributes in a tag. What I know is we can use: > should have_tag("tag#id") or should have_tag("tag.class") > to select a tag, whereas I don't know how to select an attribute and test > it! That's all covered in the assert_select docs. Here's a cheat sheet you might find useful. http://labnotes.org/svn/public/ruby/rails_plugins/assert_select/cheat/assert_select.html so you can do this: response.should have_tag("form[action=?][method=post]", foo_path(@foo)) HTH > Another problem is the tag does not have id or class sometimes, does it mean > that is no way of selecting it? > > David Chelimsky-2 wrote: > > > > On 9/13/07, Shaker <flyeminent@...> wrote: > >> I can not find much > >> information about the "should have_tag" syntax in Rspec. > > > > http://rspec.rubyforge.org/rdoc-rails/classes/Spec/Rails/Matchers.html#M000011 > > _______________________________________________ > > rspec-users mailing list > > rspec-users@... > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > View this message in context: http://www.nabble.com/Need-help-in-View-Spec-tf4439760.html#a12667582 > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users@... > http://rubyforge.org/mailman/listinfo/rspec-users > rspec-users mailing list rspec-users@... http://rubyforge.org/mailman/listinfo/rspec-users |
|
|
Re: Need help in View SpecHello
To spec the example I mentioned before, I wrote the spec as what you suggested #../view/group/index_spec.rb describe "/group/_index_spec" do it "should call JS function when click the button" do render '/group/_index' response.should have_tag("input[onclick=?]", "update()") end end However, it generated an error "Expecting a selector as the first argument". What is wrong?
|
|
|
Re: Need help in View SpecSorry, that's another spec caused the error. It is working. Thank you very much
|
|
|
Re: Need help in View SpecOn 9/13/07, Shaker <flyeminent@...> wrote:
> > Sorry, that's another spec caused the error. It is working. Thank you very > much Glad you got it worked out. Cheers, David > > Shaker wrote: > > > > Hello > > To spec the example I mentioned before, I wrote the spec as what you > > suggested > > #../view/group/index_spec.rb > > describe "/group/_index_spec" do > > it "should call JS function when click the button" do > > render '/group/_index' > > response.should have_tag("input[onclick=?]", "update()") > > end > > end > > However, it generated an error "Expecting a selector as the first > > argument". What is wrong? > > > > David Chelimsky-2 wrote: > >> > >> On 9/13/07, Shaker <flyeminent@...> wrote: > >>> > >>> Yes, I have gone through the documentation before, and I read the > >>> reference > >>> of 'assert_select' as well. But I still can not figure out a way of > >>> testing > >>> attributes in a tag. What I know is we can use: > >>> should have_tag("tag#id") or should have_tag("tag.class") > >>> to select a tag, whereas I don't know how to select an attribute and > >>> test > >>> it! > >> > >> That's all covered in the assert_select docs. Here's a cheat sheet you > >> might find useful. > >> > >> http://labnotes.org/svn/public/ruby/rails_plugins/assert_select/cheat/assert_select.html > >> > >> so you can do this: > >> > >> response.should have_tag("form[action=?][method=post]", foo_path(@foo)) > >> > >> HTH > >> > >> > >> > >> > >> > >>> Another problem is the tag does not have id or class sometimes, does it > >>> mean > >>> that is no way of selecting it? > >>> > >>> David Chelimsky-2 wrote: > >>> > > >>> > On 9/13/07, Shaker <flyeminent@...> wrote: > >>> >> I can not find much > >>> >> information about the "should have_tag" syntax in Rspec. > >>> > > >>> > > >>> http://rspec.rubyforge.org/rdoc-rails/classes/Spec/Rails/Matchers.html#M000011 > >>> > _______________________________________________ > >>> > rspec-users mailing list > >>> > rspec-users@... > >>> > http://rubyforge.org/mailman/listinfo/rspec-users > >>> > > >>> > > >>> > >>> -- > >>> View this message in context: > >>> http://www.nabble.com/Need-help-in-View-Spec-tf4439760.html#a12667582 > >>> Sent from the rspec-users mailing list archive at Nabble.com. > >>> > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users@... > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >>> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users@... > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > >> > > > > > > -- > View this message in context: http://www.nabble.com/Need-help-in-View-Spec-tf4439760.html#a12667734 > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users@... > http://rubyforge.org/mailman/listinfo/rspec-users > rspec-users mailing list rspec-users@... http://rubyforge.org/mailman/listinfo/rspec-users |
| Free embeddable forum powered by Nabble | Forum Help |