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/.
_______________________________________________
rspec-users mailing list
rspec...@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
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
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 :-)
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' } toBut it is not working,i know i am missing something.
/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
Also can you explain the first point?
Can you tell me up what i need to add to get it running atleast :-)
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.
> 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"
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.
David Chelimsky wrote:
> On Nov 11, 2009, at 5:58 AM, Amit Kulkarni <li...@ruby-forum.com> wrote:
>
>>
>> it "should map { :controller => 'home' } RESTfully" doHi David,
>> 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"
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.
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?
David Chelimsky wrote:
> On Wed, Nov 11, 2009 at 11:19 PM, Amit Kulkarni
> <li...@ruby-forum.com>wrote:
>
>> >>
>> It gets executed but i am not able to see any results as in 2 examples 2I dont know,When i run the command no result is displayed.
>> passed something like that as it comes normally.
>>
>
> Then how do you know it gets executed?
Also error is not displayed.
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 => 'f...@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 => 'te...@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
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.
Amit Kulkarni wrote:Hi David,
> 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.
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.
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.
Amit Kulkarni wrote:Hi David,
> Ok Fine.That sounds to be a good idea.
> Thanks
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.
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?
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?
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.
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.
--