Skip to content

Instantly share code, notes, and snippets.

@scudelletti
Created May 27, 2016 07:21
Show Gist options
  • Save scudelletti/2d766d512e1e5f58fa66757d783ad65c to your computer and use it in GitHub Desktop.
Save scudelletti/2d766d512e1e5f58fa66757d783ad65c to your computer and use it in GitHub Desktop.
How to avoid global constant in the specs
require 'spec_helper'
describe "Wow Coins" do
let(:klasz_class) do
Class.new do
attr_reader :title
def initialize(properties)
@title = properties[:title]
end
end
end
describe "public stuff" do
subject { !!defined?(Klasz) }
context "when I stub the contant" do
before do
stub_const("Klasz", klasz_class)
end
it { is_expected.to be(true) }
end
context "when I DO NOT stub the contant" do
it { is_expected.to be(false) }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment