From omen.king at gmail.com Mon Oct 1 00:44:16 2007 From: omen.king at gmail.com (Andrew WC Brown) Date: Mon, 1 Oct 2007 00:44:16 -0400 Subject: [rspec-users] autotest stop working, 1.0.9? In-Reply-To: <80F2BA2C-7B2F-470C-9136-3655403C219A@railsnewbie.com> References: <80F2BA2C-7B2F-470C-9136-3655403C219A@railsnewbie.com> Message-ID: I reinstalled the plugins and generated rspec but still doesn't work. On 9/30/07, Scott Taylor wrote: > > > On Sep 30, 2007, at 3:05 AM, Andrew WC Brown wrote: > > > My autotest runs but when I make changes to a spec it doesn't reload. > > I checked another application I was building that had 1.0.9 but it > > was reloading fine. > > > > How would I debug a problem such as autotest not reloading? > > One way would be to run the debugger. > > escher: which autotest > /sw/bin/autotest > > escher: rdebug /sw/bin/autotest > /sw/bin/autotest:9 require 'rubygems' > (rdb:1) > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071001/d8550b9e/attachment.html From omen.king at gmail.com Mon Oct 1 01:26:15 2007 From: omen.king at gmail.com (Andrew WC Brown) Date: Mon, 1 Oct 2007 01:26:15 -0400 Subject: [rspec-users] how to spec views Message-ID: I'm trying to spec a view but haven't done much view specing. This view render different partials depending on authentication of the user: annon, admin, player So I I'll write if conditionals in the view with the partials it "should render signup propaganda for annon users trying to view games" do render "/games/index.rhtml" @logged_in?.should eql(false) response.should render_template('_signup_propaganda') end Now for my partial I know it'll be wrapped all in a div with a class="signup_propaganda" Should I be testing for that instead? Can I write expectations for partials similar to above? When your specing views are you testing for the outputted results? it "should render signup propaganda for annon users trying to view games" do render "/games/index.rhtml" @logged_in?.should eql(false) response.should have_tag(div, "class=/"signup_propaganda/"") end How should I be writing my spec? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071001/86fc22d4/attachment.html From powerlauer at gmail.com Mon Oct 1 01:29:17 2007 From: powerlauer at gmail.com (Jesper Laursen) Date: Mon, 1 Oct 2007 07:29:17 +0200 Subject: [rspec-users] Problems with testing nested routes using mocking In-Reply-To: <470019C6.6010501@u.washington.edu> References: <470019C6.6010501@u.washington.edu> Message-ID: 2007/9/30, Ryan Tucker : > Jesper Laursen wrote: > > Hello forum > > > > I have there to files > > > > #----- virtual_host_controller.rb > > class VirtualHostsController < ApplicationController > > before_filter :capture_domain > > > > # GET /domain/1/virtual_hosts/1 > > def show > > @virtual_host = @domain.virtual_hosts.find(params[:id]) > > > > respond_to do |format| > > format.html # show.rhtml > > end > > end > > > > private > > > > def capture_domain > > if params[:domain_id].blank? > > flash[:notice] = 'Need domain.' > > redirect_to domains_url > > else > > @domain = Domain.find(params[:domain_id]) > > end > > end > > end > > #---- > > > > and > > > > > > #----- virtual_host_controller_spec.rb > > describe VirtualHostsController, "handling GET /domains/1/virtual_hosts/1" do > > > > before do > > @domain = mock_model(Domain) > > @virtual_hosts = mock("virtual_hosts") > > @virtual_host = mock("virtual_host") > > Domain.should_receive(:find).with("1").and_return(@domain) > > @domain.should_receive(:virtual_hosts).and_return(@virtual_hosts) > > @virtual_hosts.should_receive(:find).and_return(@virtual_host) > > login_as :admin > > end > > > > def do_get > > get :show, :id => "1", :domain_id => "1" > > end > > > > it "should render show template" do > > do_get > > response.should render_template('show') > > end > > > > it "should find the virtual_host requested" do > > # @domain.should_receive(:virtual_hosts).and_return(@virtual_hosts) > > @virtual_hosts.should_receive(:find).with('1').and_return(@virtual_host) > > do_get > > end > > > > it "should assign the found virtual_host for the view" do > > do_get > > assigns[:virtual_host].should equal(@virtual_host) > > end > > #----- > > > > I have a problem with these three it should-cases. How can I make them to work. > > > > The error is: > > should find the virtual_host requested > > Mock 'virtual_hosts' expected :find with ("1") once, but received it 0 times > > > > The routes are like this: > > map.resources :domains do |domains| > > domains.resources :virtual_hosts > > end > > > > What can I do? > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > Correct me if I am wrong, but in the "before do" > > @virtual_hosts.should_receive(:find).and_return(@virtual_host) > > should be > > VirtualHosts.should_receive(:find).and_return(@virtual_host) > > Since you are calling find on the class? If I change it to VirtualHost (an 's' there, give no sense), these errors raises: Spec::Mocks::MockExpectationError in 'VirtualHostsController handling GET /domains/1/virtual_hosts/1 should assign the found virtual_host for the view' Mock 'virtual_hosts' received unexpected message :find with ("1") Spec::Mocks::MockExpectationError in 'VirtualHostsController handling GET /domains/1/virtual_hosts/1 should find the virtual_host requested' Mock 'Class' expected :find with (any args) once, but received it 0 times Spec::Mocks::MockExpectationError in 'VirtualHostsController handling GET /domains/1/virtual_hosts/1 should render show template' Mock 'virtual_hosts' received unexpected message :find with ("1") Spec::Mocks::MockExpectationError in 'VirtualHostsController handling GET /domains/1/virtual_hosts/1 should be successful' Mock 'virtual_hosts' received unexpected message :find with ("1") So maybe you are a bit wrong :) I found this page, http://www.vaporbase.com/postings/Rspec_example_for_nested_resource_index_action, but unfortunately, does he not describe the same things as I am. From rctucker at u.washington.edu Mon Oct 1 01:35:10 2007 From: rctucker at u.washington.edu (Ryan Tucker) Date: Sun, 30 Sep 2007 22:35:10 -0700 Subject: [rspec-users] Problems with testing nested routes using mocking In-Reply-To: References: <470019C6.6010501@u.washington.edu> Message-ID: <4700870E.2010904@u.washington.edu> Jesper Laursen wrote: > 2007/9/30, Ryan Tucker : > >> Jesper Laursen wrote: >> >>> Hello forum >>> >>> I have there to files >>> >>> #----- virtual_host_controller.rb >>> class VirtualHostsController < ApplicationController >>> before_filter :capture_domain >>> >>> # GET /domain/1/virtual_hosts/1 >>> def show >>> @virtual_host = @domain.virtual_hosts.find(params[:id]) >>> >>> respond_to do |format| >>> format.html # show.rhtml >>> end >>> end >>> >>> private >>> >>> def capture_domain >>> if params[:domain_id].blank? >>> flash[:notice] = 'Need domain.' >>> redirect_to domains_url >>> else >>> @domain = Domain.find(params[:domain_id]) >>> end >>> end >>> end >>> #---- >>> >>> and >>> >>> >>> #----- virtual_host_controller_spec.rb >>> describe VirtualHostsController, "handling GET /domains/1/virtual_hosts/1" do >>> >>> before do >>> @domain = mock_model(Domain) >>> @virtual_hosts = mock("virtual_hosts") >>> @virtual_host = mock("virtual_host") >>> Domain.should_receive(:find).with("1").and_return(@domain) >>> @domain.should_receive(:virtual_hosts).and_return(@virtual_hosts) >>> @virtual_hosts.should_receive(:find).and_return(@virtual_host) >>> login_as :admin >>> end >>> >>> def do_get >>> get :show, :id => "1", :domain_id => "1" >>> end >>> >>> it "should render show template" do >>> do_get >>> response.should render_template('show') >>> end >>> >>> it "should find the virtual_host requested" do >>> # @domain.should_receive(:virtual_hosts).and_return(@virtual_hosts) >>> @virtual_hosts.should_receive(:find).with('1').and_return(@virtual_host) >>> do_get >>> end >>> >>> it "should assign the found virtual_host for the view" do >>> do_get >>> assigns[:virtual_host].should equal(@virtual_host) >>> end >>> #----- >>> >>> I have a problem with these three it should-cases. How can I make them to work. >>> >>> The error is: >>> should find the virtual_host requested >>> Mock 'virtual_hosts' expected :find with ("1") once, but received it 0 times >>> >>> The routes are like this: >>> map.resources :domains do |domains| >>> domains.resources :virtual_hosts >>> end >>> >>> What can I do? >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> >> Correct me if I am wrong, but in the "before do" >> >> @virtual_hosts.should_receive(:find).and_return(@virtual_host) >> >> should be >> >> VirtualHosts.should_receive(:find).and_return(@virtual_host) >> >> Since you are calling find on the class? >> > > If I change it to VirtualHost (an 's' there, give no sense), these > errors raises: > > > Spec::Mocks::MockExpectationError in 'VirtualHostsController handling > GET /domains/1/virtual_hosts/1 should assign the found virtual_host > for the view' > Mock 'virtual_hosts' received unexpected message :find with ("1") > > Spec::Mocks::MockExpectationError in 'VirtualHostsController handling > GET /domains/1/virtual_hosts/1 should find the virtual_host requested' > Mock 'Class' expected :find with (any args) once, but received it 0 times > > Spec::Mocks::MockExpectationError in 'VirtualHostsController handling > GET /domains/1/virtual_hosts/1 should render show template' > Mock 'virtual_hosts' received unexpected message :find with ("1") > > Spec::Mocks::MockExpectationError in 'VirtualHostsController handling > GET /domains/1/virtual_hosts/1 should be successful' > Mock 'virtual_hosts' received unexpected message :find with ("1") > > So maybe you are a bit wrong :) > I found this page, > http://www.vaporbase.com/postings/Rspec_example_for_nested_resource_index_action, > but unfortunately, does he not describe the same things as I am. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > You are correct, it should be VirtualHost.should_receive(:find).and_return(@virtual_host) The first, third and fourth errors might be showing up because it should be the same in the it "should find the virtual_host requested" block as well. This is because the object called @virtual_hosts does not have a method called "find" defined. From dchelimsky at gmail.com Mon Oct 1 07:31:52 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 1 Oct 2007 06:31:52 -0500 Subject: [rspec-users] autotest stop working, 1.0.9? In-Reply-To: References: <80F2BA2C-7B2F-470C-9136-3655403C219A@railsnewbie.com> Message-ID: <57c63afe0710010431i1c1af30hf22c23fce3ddadbd@mail.gmail.com> On 9/30/07, Andrew WC Brown wrote: > I reinstalled the plugins and generated rspec but still doesn't work. What is the path to the spec that you're changing? > > > On 9/30/07, Scott Taylor wrote: > > > > On Sep 30, 2007, at 3:05 AM, Andrew WC Brown wrote: > > > > > My autotest runs but when I make changes to a spec it doesn't reload. > > > I checked another application I was building that had 1.0.9 but it > > > was reloading fine. > > > > > > How would I debug a problem such as autotest not reloading? > > > > One way would be to run the debugger. > > > > escher: which autotest > > /sw/bin/autotest > > > > escher: rdebug /sw/bin/autotest > > /sw/bin/autotest:9 require 'rubygems' > > (rdb:1) > > > > Scott > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Oct 1 07:55:33 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 1 Oct 2007 06:55:33 -0500 Subject: [rspec-users] how to spec views In-Reply-To: References: Message-ID: <57c63afe0710010455ob6b16fbn40ecbcb903beb097@mail.gmail.com> On 10/1/07, Andrew WC Brown wrote: > I'm trying to spec a view but haven't done much view specing. > > This view render different partials depending on authentication of the user: > annon, admin, player > So I I'll write if conditionals in the view with the partials > > > it "should render signup propaganda for annon users trying to view games" > do > render "/games/index.rhtml" > @logged_in?.should eql(false) > response.should render_template('_signup_propaganda') > end > > Now for my partial I know it'll be wrapped all in a div with a > class="signup_propaganda" > Should I be testing for that instead? Can I write expectations for partials > similar to above? > > When your specing views are you testing for the outputted results? > > it "should render signup propaganda for annon users trying to view games" > do > render "/games/index.rhtml" > @logged_in?.should eql(false) > response.should have_tag(div, "class=/"signup_propaganda/"") > end > > How should I be writing my spec? There is no simple answer to your question. If anyone offers you one, treat it with a grain of salt. Coding by example is a process. If you're doing it right, the examples are going to change as you progress. So in this case, I might start like this: it "should render signup propaganda for annon users trying to view games" do controller.stub!(:logged_in?).and_return(false) render "/games/index.rhtml" response.should have_tag('div.signup_propaganda') end The code to make this pass could just be: