Sean Page Sean Page - 2 months ago 6
Ruby Question

RSpec 3 RuntimeError: "let declaration accessed in a `before(:context)` hook"

Here is my error

Failure/Error: @queue = FactoryGirl.create(model.to_s.underscore.to_sym)
let declaration `model` accessed in a `before(:context)` hook at:
/var/www/html/SQ-UI/spec/support/user_queue/asterisk_serialize_spec.rb:7:in `block (2 levels) in <top (required)>'

`let` and `subject` declarations are not intended to be called
in a `before(:context)` hook, as they exist to define state that
is reset between each example, while `before(:context)` exists to
define state that is shared across examples in an example group.enter code here

and here is the code where it's breaking

let(:model) { described_class } # the class that includes the concern

before(:all) do
@queue = FactoryGirl.create(model.to_s.underscore.to_sym)

I've tried removing them and moving them around but no success.


You can't refer to a let variable (or subject) in a before(:all)/before(:context) hook. Doing so was deprecated in RSpec 2 and removed from RSpec 3.

In your case it looks like you can just inline the let variable into the before(:all) block:

before(:all) do
  @queue = FactoryGirl.create(described_class.to_s.underscore.to_sym)