Hi all, I am writing scenarios for testing my routes but it is giving me error as undefined method `route_for and also for params_from. Did i miss something which i need to add in my controller My code is as follows: require File.expand_path(File.dirname(__FILE__) + ''/../spec_helper'') describe HomeController, "routes" do describe "route generation" do it "should map { :controller => ''home'', :action => ''index'' } to /home" do route_for(:controller => ''home'', :action => ''index'').should =''/home'' end it "should map { :controller => ''home'' } RESTfully" do params_from( :get, ''/home'' ).should == { :controller => ''home'', :action => ''index'' } end end end -- Posted via http://www.ruby-forum.com/.
On Tue, Nov 10, 2009 at 4:44 AM, Amit Kulkarni <lists at ruby-forum.com> wrote:> Hi all, > I am writing scenarios for testing my routes but it is giving me error > as undefined method `route_for and also for params_from. > Did i miss something which i need to add in my controller > > My code is as follows: > > require File.expand_path(File.dirname(__FILE__) + ''/../spec_helper'') > > describe HomeController, "routes" do > describe "route generation" do > it "should map { :controller => ''home'', :action => ''index'' } to > /home" do > route_for(:controller => ''home'', :action => ''index'').should => ''/home'' > end > > it "should map { :controller => ''home'' } RESTfully" do > params_from( :get, ''/home'' ).should == { :controller => ''home'', > :action => ''index'' } > end > end > end >route_to, route_for and params_from are all available in controller specs, which are identified by: 1. spec/controllers in their path (i.e. spec/controllers/foo_controller_spec 2. describe "route generation", :type => :controller do If neither of those cases is true, then you won''t have access to the right helpers and matchers. HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091110/4c8d37fc/attachment.html>
Thanks David for the information but still i am getting the same error. What i have done is: I have home controller. now i am writing route scenarios in home_controller_spec.rb which is under spec/controllers directory I tried your code which looks like as describe "route generation", :type => :HomeController do it "should map { :controller => ''home'', :action => ''index'' } to /home" do route_for(:controller => ''home'', :action => ''index'').should == ''/home'' end it "should map { :controller => ''home'' } RESTfully" do params_from( :get, ''/home'' ).should == { :controller => ''home'', :action => ''index'' } end end But it is not working,i know i am missing something. Also can you explain the first point? Can you tell me up what i need to add to get it running atleast :-) -- Posted via http://www.ruby-forum.com/.
On Wed, Nov 11, 2009 at 1:42 AM, Amit Kulkarni <lists at ruby-forum.com> wrote:> Thanks David for the information but still i am getting the same error. > What i have done is: > I have home controller. > now i am writing route scenarios in home_controller_spec.rb which is > under spec/controllers directory > > I tried your code which looks like as > > describe "route generation", :type => :HomeController do > it "should map { :controller => ''home'', :action => ''index'' } to > /home" do > route_for(:controller => ''home'', :action => ''index'').should => ''/home'' > end > > it "should map { :controller => ''home'' } RESTfully" do > params_from( :get, ''/home'' ).should == { :controller => ''home'', > :action => ''index'' } > end > end > > But it is not working,i know i am missing something. > > Also can you explain the first point? > Can you tell me up what i need to add to get it running atleast :-) >If the spec is in spec/controllers/home_controller_spec.rb, you don''t need the :type argument, so just get rid of that and you should be fine. If this still doesn''t work, please post the command you are using as well. For future reference, if you put a controller or routing spec in another directory, then you do need the :type argument, but :type means the type of spec, not the type of controller: describe "route generation", :type => :controller do HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091111/55d04a0a/attachment.html>
Hi David still no success. require File.expand_path(File.dirname(__FILE__) + ''/../spec_helper'') describe HomeController, "routes" do describe "route generation" do it "should map { :controller => ''home'', :action => ''index'' } to /home" do route_for(:controller => ''home'', :action => ''index'').should == ''/home'' end it "should map { :controller => ''home'' } RESTfully" do params_from( :get, ''/home'' ).should == { :controller => ''home'', :action => ''index'' } end end end I am using "spec home_controller_spec.rb" by going under spec/controllers/ directory. -- Posted via http://www.ruby-forum.com/.
On Nov 11, 2009, at 5:58 AM, Amit Kulkarni <lists at ruby-forum.com> wrote:> Hi David still no success. > require File.expand_path(File.dirname(__FILE__) + ''/../spec_helper'') > describe HomeController, "routes" do > describe "route generation" do > it "should map { :controller => ''home'', :action => ''index'' } to / > home" > do > route_for(:controller => ''home'', :action => ''index'').should => ''/home'' > end > > it "should map { :controller => ''home'' } RESTfully" do > params_from( :get, ''/home'' ).should == { :controller => ''home'', > :action => ''index'' } > end > end > end > > I am using "spec home_controller_spec.rb" by going under > spec/controllers/ directory.Don''t do that :) Go to the project root directory and say "spec spec/controllers/ home_controller_spec.rb"> -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
David Chelimsky wrote:> On Nov 11, 2009, at 5:58 AM, Amit Kulkarni <lists at ruby-forum.com> wrote: > >> >> it "should map { :controller => ''home'' } RESTfully" do >> params_from( :get, ''/home'' ).should == { :controller => ''home'', >> :action => ''index'' } >> end >> end >> end >> >> I am using "spec home_controller_spec.rb" by going under >> spec/controllers/ directory. > > Don''t do that :) > > Go to the project root directory and say "spec spec/controllers/ > home_controller_spec.rb"Hi David, I tried to run from the above command. It gets executed but i am not able to see any results as in 2 examples 2 passed something like that as it comes normally. -- Posted via http://www.ruby-forum.com/.
On Wed, Nov 11, 2009 at 11:19 PM, Amit Kulkarni <lists at ruby-forum.com>wrote:> David Chelimsky wrote: > > On Nov 11, 2009, at 5:58 AM, Amit Kulkarni <lists at ruby-forum.com> wrote: > > > >> > >> it "should map { :controller => ''home'' } RESTfully" do > >> params_from( :get, ''/home'' ).should == { :controller => ''home'', > >> :action => ''index'' } > >> end > >> end > >> end > >> > >> I am using "spec home_controller_spec.rb" by going under > >> spec/controllers/ directory. > > > > Don''t do that :) > > > > Go to the project root directory and say "spec spec/controllers/ > > home_controller_spec.rb" > > Hi David, > I tried to run from the above command. > It gets executed but i am not able to see any results as in 2 examples 2 > passed something like that as it comes normally. >Then how do you know it gets executed? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091112/46b79853/attachment.html>
David Chelimsky wrote:> On Wed, Nov 11, 2009 at 11:19 PM, Amit Kulkarni > <lists at ruby-forum.com>wrote: > >> >> >> It gets executed but i am not able to see any results as in 2 examples 2 >> passed something like that as it comes normally. >> > > Then how do you know it gets executed?I dont know,When i run the command no result is displayed. Also error is not displayed. But why is this happening?Also how can i run this to test my routes? -- Posted via http://www.ruby-forum.com/.
On Thu, Nov 12, 2009 at 11:32 PM, Amit Kulkarni <lists at ruby-forum.com>wrote:> David Chelimsky wrote: > > On Wed, Nov 11, 2009 at 11:19 PM, Amit Kulkarni > > <lists at ruby-forum.com>wrote: > > > >> >> > >> It gets executed but i am not able to see any results as in 2 examples 2 > >> passed something like that as it comes normally. > >> > > > > Then how do you know it gets executed? > > I dont know,When i run the command no result is displayed. > Also error is not displayed. >That likely means nothing is actually happening. Please post your spec_helper.rb. Also, what versions of rspec, rspec-rails, and rails are you using?> But why is this happening?Also how can i run this to test my routes?-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091112/f5ca3efe/attachment.html>
MY spec helper contains following code: # This file is copied to ~/spec when you run ''ruby script/generate rspec'' # from the project root directory. ENV["RAILS_ENV"] ||= ''test'' require File.expand_path(File.join(File.dirname(__FILE__),''..'',''config'',''environment'')) require ''spec'' require ''webrat'' require ''spec/autorun'' require ''spec/rails'' require File.join( Rails.root, ''spec'', ''macros'' ) # Uncomment the next line to use webrat''s matchers #require ''webrat/integrations/rspec-rails'' # Requires supporting files with custom matchers and macros, etc, # in ./support/ and its subdirectories. Dir[File.expand_path(File.join(File.dirname(__FILE__),''support'',''**'',''*.rb''))].each {|f| require f} Spec::Runner.configure do |config| config.include(ModelExampleGroupHelper, :type => :model) config.include(ControllerExampleGroupHelper, :type => :controller) # If you''re not using ActiveRecord you should remove these # lines, delete config/database.yml and disable :active_record # in your config/boot.rb config.use_transactional_fixtures = true config.use_instantiated_fixtures = false config.fixture_path = RAILS_ROOT + ''/spec/fixtures/'' config.include Webrat::Matchers, :type => :views # == Fixtures # # You can declare fixtures for each example_group like this: # describe "...." do # fixtures :table_a, :table_b # # Alternatively, if you prefer to declare them only once, you can # do so right here. Just uncomment the next line and replace the fixture # names with your fixtures. # # config.global_fixtures = :table_a, :table_b # # If you declare global fixtures, be aware that they will be declared # for all of your examples, even those that don''t use them. # # You can also declare which fixtures to use (for example fixtures for test/fixtures): # # config.fixture_path = RAILS_ROOT + ''/spec/fixtures/'' # # == Mock Framework # # RSpec uses it''s own mocking framework by default. If you prefer to # use mocha, flexmock or RR, uncomment the appropriate line: # # config.mock_with :mocha # config.mock_with :flexmock # config.mock_with :rr # # == Notes # # For more information take a look at Spec::Runner::Configuration and Spec::Runner end def login controller.stub!( :logged_in? ).and_return( true ) controller.stub!( :login_required ).and_return( true ) @current_user = mock_model( User, :id => 1, :time_zone => ''Rome'', :idiom => ''it'', :login => ''quentin'', :email => ''foo at bar.com'', :can_join? => true ) controller.stub!( :current_user ).and_return( @current_user ) end def login_as( name ) controller.stub!( :logged_in? ).and_return( true ) controller.stub!( :login_required ).and_return( true ) @current_user = users(name) controller.stub!( :current_user ).and_return( @current_user ) end def valid_channel_attributes { :brand_name => ''RspecChannel'' } end def valid_user_attributes { :login => ''testtest'', :password => ''555555'', :password_confirmation => ''555555'', :email => ''test at test.com'', :idiom => ''it'', :privacy => ''1'', } end def create_channel(args=nil) args ||= valid_channel_attributes Channel.create args end def create_user(args = nil) args ||= valid_user_attributes User.create args end #~ %w!User Contest Video Print Radio Banner Conceptl!.each do |model| #~ model.constantize.any_instance.stubs(:save_attached_files).returns(true) #~ end rspec = 1.2.9 rspec-rails - 1.2.9 rails = 2.1.2 -- Posted via http://www.ruby-forum.com/.
On Fri, Nov 13, 2009 at 2:28 AM, Amit Kulkarni <lists at ruby-forum.com> wrote:> MY spec helper contains following code: > # This file is copied to ~/spec when you run ''ruby script/generate > rspec'' > # from the project root directory. > ENV["RAILS_ENV"] ||= ''test'' > require > > File.expand_path(File.join(File.dirname(__FILE__),''..'',''config'',''environment'')) > require ''spec'' > require ''webrat'' > require ''spec/autorun'' > require ''spec/rails'' > > require File.join( Rails.root, ''spec'', ''macros'' ) > # Uncomment the next line to use webrat''s matchers > #require ''webrat/integrations/rspec-rails'' > > # Requires supporting files with custom matchers and macros, etc, > # in ./support/ and its subdirectories. > > Dir[File.expand_path(File.join(File.dirname(__FILE__),''support'',''**'',''*.rb''))].each > {|f| require f} > > Spec::Runner.configure do |config| > config.include(ModelExampleGroupHelper, :type => :model) > config.include(ControllerExampleGroupHelper, :type => :controller) > # If you''re not using ActiveRecord you should remove these > # lines, delete config/database.yml and disable :active_record > # in your config/boot.rb > config.use_transactional_fixtures = true > config.use_instantiated_fixtures = false > config.fixture_path = RAILS_ROOT + ''/spec/fixtures/'' > > config.include Webrat::Matchers, :type => :views > # == Fixtures > # > # You can declare fixtures for each example_group like this: > # describe "...." do > # fixtures :table_a, :table_b > # > # Alternatively, if you prefer to declare them only once, you can > # do so right here. Just uncomment the next line and replace the > fixture > # names with your fixtures. > # > # config.global_fixtures = :table_a, :table_b > # > # If you declare global fixtures, be aware that they will be declared > # for all of your examples, even those that don''t use them. > # > # You can also declare which fixtures to use (for example fixtures for > test/fixtures): > # > # config.fixture_path = RAILS_ROOT + ''/spec/fixtures/'' > # > # == Mock Framework > # > # RSpec uses it''s own mocking framework by default. If you prefer to > # use mocha, flexmock or RR, uncomment the appropriate line: > # > # config.mock_with :mocha > # config.mock_with :flexmock > # config.mock_with :rr > # > # == Notes > # > # For more information take a look at Spec::Runner::Configuration and > Spec::Runner > end > > def login > controller.stub!( :logged_in? ).and_return( true ) > controller.stub!( :login_required ).and_return( true ) > @current_user = mock_model( User, :id => 1, :time_zone => ''Rome'', > :idiom => ''it'', :login => ''quentin'', :email => ''foo at bar.com'', :can_join? > => true ) > controller.stub!( :current_user ).and_return( @current_user ) > end > > def login_as( name ) > controller.stub!( :logged_in? ).and_return( true ) > controller.stub!( :login_required ).and_return( true ) > @current_user = users(name) > controller.stub!( :current_user ).and_return( @current_user ) > end > > def valid_channel_attributes > { > :brand_name => ''RspecChannel'' > } > end > > def valid_user_attributes > { > :login => ''testtest'', :password => ''555555'', :password_confirmation > => ''555555'', :email => ''test at test.com'', :idiom => ''it'', :privacy => ''1'', > } > end > > def create_channel(args=nil) > args ||= valid_channel_attributes > Channel.create args > end > > def create_user(args = nil) > args ||= valid_user_attributes > User.create args > end > > > #~ %w!User Contest Video Print Radio Banner Conceptl!.each do |model| > #~ > model.constantize.any_instance.stubs(:save_attached_files).returns(true) > #~ end > > rspec = 1.2.9 > rspec-rails - 1.2.9 > rails = 2.1.2 >There''s your problem. The last version of rspec that supports rails 2.1.x is 1.1.12. See http://github.com/dchelimsky/rspec-rails/blob/master/History.rdoc. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091113/aae47c87/attachment.html>
Oh that means if i am using rails version 2.1.2 or more then i need to have rspec version 1.1.12. In that case i need to remove the latest version and install rspec 1.1.12. I will do it and update you asap. Thanks a lot David. -- Posted via http://www.ruby-forum.com/.
Amit Kulkarni wrote:> Oh that means if i am using rails version 2.1.2 or more then i need to > have rspec version 1.1.12. > In that case i need to remove the latest version and install rspec > 1.1.12. > I will do it and update you asap. > Thanks a lot David.Hi David, As per the doc i updated my gems.Version of my gems are : Rails : 2.1.2 Rspec : 1.1.12 Rspec-Rails : 1.1.12 But when i run my files same error is being displayed. I am working on Windows vista.Does this may impact running my spec? Please suggest. -- Posted via http://www.ruby-forum.com/.
On Tue, Nov 17, 2009 at 4:53 AM, Amit Kulkarni <lists at ruby-forum.com> wrote:> Amit Kulkarni wrote: > > Oh that means if i am using rails version 2.1.2 or more then i need to > > have rspec version 1.1.12. > > In that case i need to remove the latest version and install rspec > > 1.1.12. > > I will do it and update you asap. > > Thanks a lot David. > > Hi David, > As per the doc i updated my gems.Version of my gems are : > Rails : 2.1.2 > Rspec : 1.1.12 > Rspec-Rails : 1.1.12 > > But when i run my files same error is being displayed. > I am working on Windows vista.Does this may impact running my spec? > Please suggest. >This back and forth is not productive. Please zip up the app and send it to me so I can see the whole thing in context. Thanks, David -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091117/526b4553/attachment-0001.html>
Ok Fine.That sounds to be a good idea. Thanks -- Posted via http://www.ruby-forum.com/.
Amit Kulkarni wrote:> Ok Fine.That sounds to be a good idea. > ThanksHi David, Good news,My routing scenarios are working now. I dont know how but it did.I was going to mail you the app but it is working fine now. -- Posted via http://www.ruby-forum.com/.
On Thu, Nov 26, 2009 at 1:21 AM, Amit Kulkarni <lists at ruby-forum.com> wrote:> Amit Kulkarni wrote: > > Ok Fine.That sounds to be a good idea. > > Thanks > > Hi David, > Good news,My routing scenarios are working now. > I dont know how but it did.I was going to mail you the app but it is > working fine now. > >Excellent! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091126/ae0bc606/attachment.html>
Hi David, I have some query regarding running spec command. When i tried to run normal testcase by command "spec test_controller_spec.rb" then that particular test case runs but the routing testcase fails. Now if i run through the command "spec spec/controllers/test_controller_spec.rb" then all the spec runs including the routing spec. Can you tell me why is this happening? -- Posted via http://www.ruby-forum.com/.
On Mon, Dec 7, 2009 at 5:32 AM, Amit Kulkarni <lists at ruby-forum.com> wrote:> Hi David, > I have some query regarding running spec command. > When i tried to run normal testcase by command "spec > test_controller_spec.rb" > then that particular test case runs but the routing testcase fails. > > Now if i run through the command "spec > spec/controllers/test_controller_spec.rb" then all the spec runs > including the routing spec. > > Can you tell me why is this happening? >rspec-rails creates different ExampleGroup subclasses for each type of spec (model, view, controller, helper). It knows which type to create based on the presence of "spec/controllers" (in this case) in the file''s runtime path, so you need to run specs from the project root in order for rspec to make this determination. HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091207/f4324198/attachment.html>
Thanks David. Also i am little bit confused regarding routes. Consider a routing example it "should map { :controller => ''channels'', :action => ''new'' } to /channels/new" do route_for(:controller => "channels", :action => "new").should == "/channels/new" end Now i can see all the routing methods by rake routes.In that i can see this new action defined. Now imagine if i write an action which is not defined in the rake routes then instead of failing it is passing.For e.g. it "should map { :controller => ''channels'', :action => ''test'' } to /channels/test" do route_for(:controller => "channels", :action => "test").should == "/channels/test" end Now here ''test'' action is not defined in the routes.So it should fail but it isn''t. May be i am missing something here. -- Posted via http://www.ruby-forum.com/.
2009/12/14 Amit Kulkarni <lists at ruby-forum.com>> Thanks David. > Also i am little bit confused regarding routes. > > Consider a routing example > > it "should map { :controller => ''channels'', :action => ''new'' } to > /channels/new" do > route_for(:controller => "channels", :action => "new").should => "/channels/new" > end > > Now i can see all the routing methods by rake routes.In that i can see > this new action defined. > > Now imagine if i write an action which is not defined in the rake routes > then instead of failing it is passing.For e.g. > > it "should map { :controller => ''channels'', :action => ''test'' } to > /channels/test" do > route_for(:controller => "channels", :action => "test").should => "/channels/test" > end > > Now here ''test'' action is not defined in the routes.So it should fail > but it isn''t. > May be i am missing something here. > -- >Are you sure you have the default last two lines commented out in routes.rb. If you haven''t they will match that action - I think. All best Andrew> Posted via http://www.ruby-forum.com/. > _______________________________________________ > 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/20091214/7b90f2be/attachment.html>
Yes,Thanks a lot Andrew. The last two lines were not commented in routes.rb because of that it was matching default.Now i commented out those line and it was catching if undefined routes are given. -- Posted via http://www.ruby-forum.com/.