Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

paths are not defined in helper specs

I've just upgraded my Rails version from 4.2.6 to 5.0.0.rc1 and using RSpec version 3.5.0.beta4.

Problem is; I have a method which calls root_path in my helper and paths are not defined in helper specs. Issue started after version upgrade.

I'm getting the following error when I run my helper spec;

NoMethodError:
       undefined method `root_path' for #<#<Class:0x00000002749080>:0x00000011f3e650>

I've tried to add following line to my helper;

include Rails.application.routes.url_helpers

But now error is the following;

NameError:
       undefined local variable or method `default_url_options' for #<#<Class:0x00000001efa550>:0x0000001784ccd8>

How can I define path helpers for helper specs or default_url_options?

like image 375
beydogan Avatar asked Jun 22 '16 15:06

beydogan


1 Answers

This seems like it may be a bug with RSpec, one thing you can do in your helper specs is add the necessary methods yourself.

describe MyHelper do
  context "doing something" do
  helper do
    include Rails.application.routes.url_helpers

    def default_url_options
      {}
    end
  end

  it "should work" do
    expect(helper.run_it).to be_truthy
  end
end
like image 188
ObjectNameDisplay Avatar answered Nov 01 '22 11:11

ObjectNameDisplay