[rspec-users] [rails] url_for host and protocol not set when full spec suite run

David Chelimsky dchelimsky at gmail.com
Wed Sep 15 23:51:48 EDT 2010

On Sep 15, 2010, at 1:05 PM, Michael Kintzer wrote:

> rspec (2.0.0.beta.19)
> rails (3.0.0)
> authlogic (2.1.6)
> bartt-ssl_requirement (1.2.3)
> RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.4.0]
> Hi,
> I'm getting different results when running a Rails 3 scaffold generated controller example depending on whether or not I run 'rspec spec' or 'rspec spec/controllers'.   The difference occurs when evaluating the dynamic route methods with for '_url', e.g.  my_model_url   I'm using Authlogic and SslRequirement as well.  The issue may be in either of those libraries, but the only difference is how I run the spec suite.   I disable the Ssl requirement check in the test.rb environment file.
> Assume I generated the scaffold code with:  "rails g scaffold scaffold" to create a "Scaffold" model.
> See relevant code here: http://gist.github.com/581130
> When I run 'rspec spec/controllers', the example in question passes.  I placed debug code in url_for.rb (bartt-ssl_requirement-1.2.3) to parse the options passed to url_for and they include the :host and :protocol parameters,  :host => "test.host", :protocol => "http://".
> When I run 'rspec spec', the example in question fails.   The url_for options are missing both the :host and :protocol parameters.   If I manully pass those into the my_model_url method, the example will pass.   If I use the _path version of the route method, the example passes.
> The stack trace in the failing case is (path to gems directory omitted):
> 1) ScaffoldsController POST create with valid params redirects to the created scaffold
>     Failure/Error: response.should redirect_to(scaffold_url(mock_scaffold))
>     Missing host to link to! Please provide :host parameter or set default_url_options[:host]
>     # .../actionpack-3.0.0/lib/action_dispatch/routing/route_set.rb:473:in `url_for_without_non_ssl_host'
>     # .../bartt-ssl_requirement-1.2.3/lib/url_for.rb:44:in `url_for_without_secure_option'
>     # .../gems/bartt-ssl_requirement-1.2.3/lib/url_for.rb:32:in `url_for'
>     # .../actionpack-3.0.0/lib/action_dispatch/routing/url_for.rb:132:in `url_for'
>     # .../actionpack-3.0.0/lib/action_dispatch/routing/route_set.rb:195:in `factor_library_url'
>     # ./spec/controllers/scaffolds_controller_spec.rb:70
>     # .../activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `inject'
> So, I'm stumped as to why 'rspec spec' is behaving differently from 'rspec spec/controllers' with respect to generating the appropriate url_for options.

This sort of problem usually boils down to something interacting with global state - something that is only getting loaded when you run the full suite. To narrow it down, try running subsets of the directories:

rspec spec/controllers spec/requests
rspec spec/controllers spec/views
rspec spec/controllers spec/models



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100915/a1a990b4/attachment.html>

More information about the rspec-users mailing list