I am trying to write a Rspec test for a ruby function which lives in a new file and references an instance variable inside a controller file. I am having unable to mock anything for the line
flag = @domain.feature?("BrandNewFeature")
When I run the above code I get error on line
flag = @domain.feature?("BrandNewFeature")
saying
#<NoMethodError: undefined method `feature?' for nil:NilClass>
Any help is greatly appreciated
play.rb
Api.controllers :playbooks do
before do
@domain = account.domain
def get_filter(param)
f = find_lists(param)
play_help.rb
module ApiHelpers
def find_lists(params)
flag = @domain.feature?("BrandNewFeature")
folder = ListQueries.folders(params) if flag
folder
play_help_spec.rb
require "unit/spec_help"
require_project "api/helpers/play_help.rb"
RSpec.describe ApiHelp do
describe "#find_matching_lists" do
allow(list_queries).to receive(:folders).and_return(folders)
binding.pry
domainDouble = double()
allow(Domain).to receive(:new).and_return(domainDouble)
allow(domainDouble).to receive(:feature?).with("BrandNewFeature").and_return(true)
accountis but it seems like mockingaccount.domainwould be better and easier in this scenario.