catch22
catch22

Reputation: 1693

undefined method `allow' for #<RSpec:: Rspec 3.6.0

I'm new to Rails and specially to writing tests. I keep getting the error undefined method allow and undefined method allow_any_instance_of' when I run the test. I've checked Rspec > 3 should accept the allow syntax, what is the issue in my code?

describe "GET #show" do

    let(:sample_json_list) {
      "{\"files\":[{\"title\":\"discourse-2017-08-24-085545-v20170803123704.sql.gz\",\"id\":\"0B7WjYjWZJv_4MENlYUM2SjkyU1E\",\"size\":\"14070939\",\"created_at\":\"2017-08-24T06:56:21.698+00:00\"}]}"
    }

    before {
      allow_any_instance_of(DiscourseDownloadFromDrive::DriveDownloader).to receive(:json_list).and_return(sample_json_list)
    }

    it "renders the json" do
      get :show
      response.body.should == sample_json_list
    end

  end

Upvotes: 1

Views: 2193

Answers (1)

rony36
rony36

Reputation: 3339

Alright, first of all configure expect syntax. Would be look like:

# spec_helper.rb
RSpec.configure do |config|
  config.expect_with :rspec do |c|
    c.syntax = :expect
  end
end

And now allow_any_instance_of will work like charm. But, then syntax would be look like:

it "renders the json" do
  get :show
  expect(response.body).to eq(sample_json_list)
end

Cheers!

Upvotes: 2

Related Questions