Rails helper problem

Hi guys,

I’m building a application using subdomains feature like basecamp. To
create the correct link reference I use a with_subdomain function whch
take the subdmain name and create a subdomain name like
subdomain.mydomain.com.
So to teste that a account information view have the link to right
domain I wrote the test above:
describe SubdomainController do
render_views
it “should have a link to subdomain” do
post :create, :subdomain => @attr
response.should have_selector(‘a’, :href =>
with_subdomain(‘test’), :content => with_subdomain(‘test’))
end
end

But I get the error message below:

NoMethodError:
undefined method `with_subdomain’ for
#RSpec::Core::ExampleGroup::Nested_5::Nested_2::Nested_2:0x8ebf124

And I included the url_helper that has the function on my
ApplicationController like this:

class ApplicationController < ActionController::Base
include UrlHelper

end

So, if you have any idea what is wrong, where I miss, please help me.

Thanks,

Pablo Lacerda de Miranda
[email protected]
+55 11 8701-1086

On 1 May 2011, at 18:29, Pablo L. de Miranda wrote:

   response.should have_selector('a', :href =>

And I included the url_helper that has the function on my
ApplicationController like this:

class ApplicationController < ActionController::Base
include UrlHelper

end

So, if you have any idea what is wrong, where I miss, please help me.

You’re calling the ‘with_subdomain’ method from within your spec file,
but you haven’t included the module it’s defined in (UrlHelper) in your
spec file. So, in the context of that spec, ‘with_subdomain’ is not
defined – the fact that you’ve included it in your
ApplicationController class doesn’t affect the code in the spec.

As an aside, is this example intended to test that the ‘with_subdomain’
method is working correctly? Because it looks like you’re specifying
that “the output of with_subdomain should equal the output of
with_subdomain”, which will always pass, even if with_subdomain is
actually outputting the wrong thing. That’s fine if you’re speccing
with_subdomain elsewhere (i.e. in a helper spec), but I thought it was
worth pointing out.

Chris

Hi Chris,

Thank you for your help, i inclued the UrlHelper on my spec_helper
file and it worked.
Yes the intent is just check with the link is created. I have other
test to asset that with_subdomain build the correct path to subdomain.

Thanks,

Pablo Lacerda de Miranda
[email protected]
+55 11 8701-1086