0

By https://relishapp.com/rspec/rspec-rails/docs/directory-structure, we can define a new type. Currently, I am using keynote(MVP for rails), so there is a new type: presenter if I define

RSpec.configure do |config|
  config.infer_spec_type_from_file_location!
end

However, if I do something like

expect(presenter).to receive(:current_user).and_return(user)

rspec reports

NameError: undefined local variable or method `presenter'

But as we know,

expect(view).to receive(:current_user).and_return(user)

Here view is a variable in rspec. How to make presenter the same way as view or controller?

new2cpp
  • 3,311
  • 5
  • 28
  • 39

1 Answers1

1

You can add metadata for custom directories like so:

RSpec.configure do |config| config.define_derived_metadata(:file_path => Regexp.new('/spec/presenters/')) do |metadata| metadata[:type] = :presenter end end

I'm not sure what you actually are trying to achieve though. What would you expect the presenter variable you reference above to be exactly? If you want to mock or stub objects you are best off being very specific about what those objects are.

Paul Byrne
  • 1,563
  • 18
  • 24