I’m having an issue with using the let function provided by rspec:
In app/spec/class_spec.rb:
require 'spec_helper'
module App
describe Class do
let(:instance) {Class.new('param')}
describe "#method" do
it "does something" do
instance.method(...)
# clever test code
end
.
.
.
end
I’ve been following the RSpec book, and according to its examples (which worked through!) let should give me access to the variable instance for the rest of the ‘describe Class’ block. But I get the error:
Uninitialized constant App::instance
I also tried adding this code to no avail:
before :all do
instance
end
What am I doing wrong?
Instead of
just use:
and everything should be fine
hint: instead
let(:instance) {Class.new('param')}you could writelet(:instance) {described_class.new('param')}. It’s more clever.