Well, I''be looking for test my views with rspec, looking the documentation at http://rspec.info/rails/writing/views.html we see some examples, in RSpec 2 the response was deprecated and now I''m using the rendered instead, but this code describe "tags/search.html.erb" do it "should be have an p when no company for the tag was found" do assigns[:name] = "Teste" render rendered.should have_tag(''h4'', "Visualizando empresas pela Tag Teste") end end and I get : Failures: 1) tags/search.html.erb should be have an p when no company for the tag was found Failure/Error: rendered.should have_tag(''h4'', "Visualizando empresas pela Tag Teste") undefined method `has_tag?'' for #<String:0x7f45cc59a880> # ./spec/views/tags/search.html.erb_spec.rb:9 I don''t know what method we use to check my views? thanks for all regards
On Oct 12, 2010, at 6:38 PM, Rafael Felix wrote:> Well, I''be looking for test my views with rspec, looking the > documentation at http://rspec.info/rails/writing/views.html we see > some examples, in RSpec 2 the response was deprecated and now I''m > using the rendered instead, but this code > > describe "tags/search.html.erb" do > it "should be have an p when no company for the tag was found" do > assigns[:name] = "Teste" > render > rendered.should have_tag(''h4'', "Visualizando empresas pela Tag > Teste") > end > end > > and I get : > > > Failures: > 1) tags/search.html.erb should be have an p when no company for the > tag was found > Failure/Error: rendered.should have_tag(''h4'', "Visualizando > empresas pela Tag Teste") > undefined method `has_tag?'' for #<String:0x7f45cc59a880> > # ./spec/views/tags/search.html.erb_spec.rb:9 > > I don''t know what method we use to check my views?If you''re using webrat, use have_selector or have_xpath. Otherwise, use Rails'' assert_select. HTH, David
Changing my test, for user assert_select, an new error is raised it "should be have an p when no company for the tag was found" do assigns[:name] = "Teste" render rendered.should assert_select(''h4'', "Visualizando empresas pela Tag") end And the error: Failures: 1) tags/search.html.erb should be have an p when no company for the tag was found Failure/Error: rendered.should assert_select(''h4'', "Visualizando empresas pela Tag") undefined method `matches?'' for #<Array:0x7f41afa22388> # ./spec/views/tags/search.html.erb_spec.rb:7 thanks for response On Oct 12, 9:24?pm, David Chelimsky <dchelim... at gmail.com> wrote:> On Oct 12, 2010, at 6:38 PM, Rafael Felix wrote: > > > > > > > Well, I''be looking for test my views with rspec, looking the > > documentation athttp://rspec.info/rails/writing/views.htmlwe see > > some examples, in RSpec 2 the response was deprecated and now I''m > > using the rendered instead, but this code > > > describe "tags/search.html.erb" do > > ?it "should be have an p when no company for the tag was found" do > > ? ?assigns[:name] = "Teste" > > ? ?render > > ? ?rendered.should have_tag(''h4'', "Visualizando empresas pela Tag > > Teste") > > ?end > > end > > > and I get : > > > Failures: > > ?1) tags/search.html.erb should be have an p when no company for the > > tag was found > > ? ? Failure/Error: rendered.should have_tag(''h4'', "Visualizando > > empresas pela Tag Teste") > > ? ? undefined method `has_tag?'' for #<String:0x7f45cc59a880> > > ? ? # ./spec/views/tags/search.html.erb_spec.rb:9 > > > I don''t know what method we use to check my views? > > If you''re using webrat, use have_selector or have_xpath. Otherwise, use Rails'' assert_select. > > HTH, > David > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
On Oct 12, 2010, at 7:33 PM, Rafael Felix wrote:> > On Oct 12, 9:24 pm, David Chelimsky <dchelim... at gmail.com> wrote: >> On Oct 12, 2010, at 6:38 PM, Rafael Felix wrote: >> >> >> >> >> >>> Well, I''be looking for test my views with rspec, looking the >>> documentation athttp://rspec.info/rails/writing/views.htmlwe see >>> some examples, in RSpec 2 the response was deprecated and now I''m >>> using the rendered instead, but this code >> >>> describe "tags/search.html.erb" do >>> it "should be have an p when no company for the tag was found" do >>> assigns[:name] = "Teste" >>> render >>> rendered.should have_tag(''h4'', "Visualizando empresas pela Tag >>> Teste") >>> end >>> end >> >>> and I get : >> >>> Failures: >>> 1) tags/search.html.erb should be have an p when no company for the >>> tag was found >>> Failure/Error: rendered.should have_tag(''h4'', "Visualizando >>> empresas pela Tag Teste") >>> undefined method `has_tag?'' for #<String:0x7f45cc59a880> >>> # ./spec/views/tags/search.html.erb_spec.rb:9 >> >>> I don''t know what method we use to check my views? >> >> If you''re using webrat, use have_selector or have_xpath. Otherwise, use Rails'' assert_select.Please post inline or at the bottom. It makes it easier to follow the conversation. I moved your post to the bottom:> Changing my test, for user assert_select, an new error is raised > > it "should be have an p when no company for the tag was found" do > assigns[:name] = "Teste" > render > rendered.should assert_select(''h4'', "Visualizando empresas pela > Tag")assert_select is a Rails assertion that works by itself, not an RSpec matcher. Use it like this: assert_select(''h4'', "Visualizando empresas pela Tag") HTH, David> end > > And the error: > > Failures: > 1) tags/search.html.erb should be have an p when no company for the > tag was found > Failure/Error: rendered.should assert_select(''h4'', "Visualizando > empresas pela Tag") > undefined method `matches?'' for #<Array:0x7f41afa22388> > # ./spec/views/tags/search.html.erb_spec.rb:7 > > thanks for response
Woah, now works the test, thanks for response. Why the have_tag has removed from RSpec 2? regards On Oct 12, 9:37?pm, David Chelimsky <dchelim... at gmail.com> wrote:> On Oct 12, 2010, at 7:33 PM, Rafael Felix wrote: > > > > > > > > > On Oct 12, 9:24 pm, David Chelimsky <dchelim... at gmail.com> wrote: > >> On Oct 12, 2010, at 6:38 PM, Rafael Felix wrote: > > >>> Well, I''be looking for test my views with rspec, looking the > >>> documentation athttp://rspec.info/rails/writing/views.htmlwesee > >>> some examples, in RSpec 2 the response was deprecated and now I''m > >>> using the rendered instead, but this code > > >>> describe "tags/search.html.erb" do > >>> ?it "should be have an p when no company for the tag was found" do > >>> ? ?assigns[:name] = "Teste" > >>> ? ?render > >>> ? ?rendered.should have_tag(''h4'', "Visualizando empresas pela Tag > >>> Teste") > >>> ?end > >>> end > > >>> and I get : > > >>> Failures: > >>> ?1) tags/search.html.erb should be have an p when no company for the > >>> tag was found > >>> ? ? Failure/Error: rendered.should have_tag(''h4'', "Visualizando > >>> empresas pela Tag Teste") > >>> ? ? undefined method `has_tag?'' for #<String:0x7f45cc59a880> > >>> ? ? # ./spec/views/tags/search.html.erb_spec.rb:9 > > >>> I don''t know what method we use to check my views? > > >> If you''re using webrat, use have_selector or have_xpath. Otherwise, use Rails'' assert_select. > > Please post inline or at the bottom. It makes it easier to follow the conversation. I moved your post to the bottom: > > > Changing my test, for user assert_select, an new error is raised > > > it "should be have an p when no company for the tag was found" do > > ? ?assigns[:name] = "Teste" > > ? ?render > > ? ?rendered.should assert_select(''h4'', "Visualizando empresas pela > > Tag") > > assert_select is a Rails assertion that works by itself, not an RSpec matcher. Use it like this: > > assert_select(''h4'', "Visualizando empresas pela Tag") > > HTH, > David > > > ?end > > > And the error: > > > Failures: > > ?1) tags/search.html.erb should be have an p when no company for the > > tag was found > > ? ? Failure/Error: rendered.should assert_select(''h4'', "Visualizando > > empresas pela Tag") > > ? ? undefined method `matches?'' for #<Array:0x7f41afa22388> > > ? ? # ./spec/views/tags/search.html.erb_spec.rb:7 > > > thanks for response > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
On Oct 12, 2010, at 7:57 PM, Rafael Felix wrote:> On Oct 12, 9:37 pm, David Chelimsky <dchelim... at gmail.com> wrote: >> On Oct 12, 2010, at 7:33 PM, Rafael Felix wrote: >> >>> On Oct 12, 9:24 pm, David Chelimsky <dchelim... at gmail.com> wrote: >>>> On Oct 12, 2010, at 6:38 PM, Rafael Felix wrote: >> >>>>> Well, I''be looking for test my views with rspec, looking the >>>>> documentation athttp://rspec.info/rails/writing/views.htmlwesee >>>>> some examples, in RSpec 2 the response was deprecated and now I''m >>>>> using the rendered instead, but this code >> >>>>> describe "tags/search.html.erb" do >>>>> it "should be have an p when no company for the tag was found" do >>>>> assigns[:name] = "Teste" >>>>> render >>>>> rendered.should have_tag(''h4'', "Visualizando empresas pela Tag >>>>> Teste") >>>>> end >>>>> end >> >>>>> and I get : >> >>>>> Failures: >>>>> 1) tags/search.html.erb should be have an p when no company for the >>>>> tag was found >>>>> Failure/Error: rendered.should have_tag(''h4'', "Visualizando >>>>> empresas pela Tag Teste") >>>>> undefined method `has_tag?'' for #<String:0x7f45cc59a880> >>>>> # ./spec/views/tags/search.html.erb_spec.rb:9 >> >>>>> I don''t know what method we use to check my views? >> >>>> If you''re using webrat, use have_selector or have_xpath. Otherwise, use Rails'' assert_select. >> >> Please post inline or at the bottom. It makes it easier to follow the conversation. I moved your post to the bottom: >> >>> Changing my test, for user assert_select, an new error is raised >> >>> it "should be have an p when no company for the tag was found" do >>> assigns[:name] = "Teste" >>> render >>> rendered.should assert_select(''h4'', "Visualizando empresas pela >>> Tag") >> >> assert_select is a Rails assertion that works by itself, not an RSpec matcher. Use it like this: >> >> assert_select(''h4'', "Visualizando empresas pela Tag")I had to move your post again. Please post inline or at the bottom.> Woah, now works the test, thanks for response. Why the have_tag has > removed from RSpec 2?have_tag wrapped assert_select in a way that was very brittle. Also Webrat and Capybara matchers are better :) Cheers, David>>> end >> >>> And the error: >> >>> Failures: >>> 1) tags/search.html.erb should be have an p when no company for the >>> tag was found >>> Failure/Error: rendered.should assert_select(''h4'', "Visualizando >>> empresas pela Tag") >>> undefined method `matches?'' for #<Array:0x7f41afa22388> >>> # ./spec/views/tags/search.html.erb_spec.rb:7 >> >>> thanks for response >>
David Chelimsky wrote in post #949683:> have_tag wrapped assert_select in a way that was very brittle. Also > Webrat and Capybara matchers are better :)Any tips on how we can use the Capybara matchers in our helper specs? Seems like a reasonable thing to want to do, since helpers are typically used to put together pieces of html. -Steve -- Posted via http://www.ruby-forum.com/.
On Jan 5, 2011, at 4:06 PM, Steve Hull wrote:> David Chelimsky wrote in post #949683: >> have_tag wrapped assert_select in a way that was very brittle. Also >> Webrat and Capybara matchers are better :) > > Any tips on how we can use the Capybara matchers in our helper specs? > Seems like a reasonable thing to want to do, since helpers are typically > used to put together pieces of html.Capybara does not support them yet. It''s in the works though. Check the Capybara tracker for more info.> > -Steve > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Rafael Felix wrote in post #949668:> > I don''t know what method we use to check my views? > > thanks for all > regardsif you want to test views with have_tag and rspec2 try this gem: https://rubygems.org/gems/rspec2-rails-views-matchers -- Posted via http://www.ruby-forum.com/.