6

One of my specs fails when I run it via "rake spec" but passes when I use the RSpec executable "spec". The spec fails when I use a url helper in a ActionMailer view. The error message is:

auction_url failed to generate from {:action=>"show", :state=>"asd", :slug=>"asd", :controller=>"auctions"}, expected: {:action=>"show", :controller=>"auctions"}, diff: {:state=>"asd", :slug=>"asd"}

:state and :slug are required attributes for the url, though. The route looks like this:

map.auction ':state/:slug', :controller => 'auctions', :action => 'show'

I set the host, which is needed to use the url helpers in ActionMailer views, in the environment files:

ActionMailer::Base.default_url_options[:host] = 'myhost.com'

What could be the problem? Why is "rake spec" behaving differently from "spec spec"? Anything that is loaded/not loaded when using one or the other?

Manuel Meurer
  • 3,238
  • 6
  • 35
  • 50
  • It even works when invoked via "ruby spec/..." so it must be something with my rake environment / Rakefile. The contents of my Rakefile haven't been changed from the standard stuff Rails gave me: require(File.join(File.dirname(__FILE__), 'config', 'boot')) require 'rake' require 'rake/testtask' require 'rake/rdoctask' require 'tasks/rails' Please, anyone, I'm losing my mind over this! – Manuel Meurer Mar 17 '10 at 23:10
  • My answer was deleted (courtesy of @bhargav-rao) as a duplicated of http://stackoverflow.com/questions/15701298/rspec-spec-rake-spec-gives-different-result/41877864#41877864 – Claudio Floreani Jan 26 '17 at 16:25

1 Answers1

1

I realize this is a bit old, but anyway - I just ran into the same problem, not for the first time either. Then, when I started inserting debug statements into the failing spec to figure out what was going on - rake spec worked again. So I suspect some sort of caching going on when spec is involved with rake. If this occurs again, maybe try running

rake tmp:cache:clear

or even

rake tmp:clear
Thilo
  • 17,565
  • 5
  • 68
  • 84