stubbing File.expand_path in rspec/rails 4 -


i have multiple calls file.expand_path(rails.root) in code

for testing created following configuration in spec/support

rspec.configure |config|   config.before(:each)     file.stub(:expand_path).and_return("spec/fs")   end end 

so instead of "/home/user/" each request file.expand_path returns "spec/fs/"

it worked while on rails 3

however after moving rails 4, tests started throwing following error:

 failure/error: let(:category) { build(:category) }  loaderror:    cannot load such file -- spec/fs 

why appear/how can fix that?

ps.

tests/models basic, strangely test case fails:

#in class def first method(category)   "#{file.expand_path(rails.root)}/public/collections/#{self.name}/_new/#{category.name.downcase}" end  #in rspec describe "#first_method"   { expect(collection.first_method(category)).to be_instance_of(string) } end 

but 1 doesn't!

#in class def second_method   "#{file.expand_path(rails.root)}/public/collections/#{self.name}/_new/" end  #in rspec describe "#second_method"   { expect(collection.second_method).to be_instance_of(string) } end 

category factory being simple as:

factorygirl.define   factory :category     name "testcategory"   end end 

built simple

let(:category) { build(:category) } 

however seems stub failure occurs while building :category factory

file.expand_path commonly used method. not surprised if rails, rspec or factorygirl software relied on part of code gets executed after double put in place (e.g. load category model code). verify printing stack trace or going debugger when gets invoked , seeing are.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -