small medium large xlarge

Generic-user-small
18 Dec 2017, 18:38
Denis S Dujota (13 posts)

i started working on the failing validations portions, and i am getting a scope error ~~~ context “when the expense fails validation” do let(:expense) { {‘some’ => ‘data’} }

    before do
      allow(ledger).to receive(:record)
        .with(expense)
        .and_return(RecordResult.new(false, 417, 'Expense Incomplete'))
    end

    it 'returns an error message'
    post '/expenses', JSON.generate(expense)

    parsed = JSON.parse(last_response.body)
    expect(parsed).to include('error' => 'Expense Incomplete')

    it 'responds with 422 (Unprocessable entity)'
    post '/expenses', JSON.generate(expense)

    expect(last_response.status).to eq(422)
  end ~~~

below is the error message, it’s telling me i cant call the before action on this context block

Failure/Error:
  raise WrongScopeError,
        "`#{name}` is not available on an example group (e.g. a " \
        "`describe` or `context` block). It is only available from " \
        "within individual examples (e.g. `it` blocks) or from " \
        "constructs that run in the scope of an example (e.g. " \
        "`before`, `let`, etc)."

  `expense` is not available on an example group (e.g. a `describe` or `context` block). It is only available from within individual examples (e.g. `it` blocks) or from constructs that run in the scope of an example (e.g. `before`, `let`, etc).
# ./api_spec.rb:53:in `block (3 levels) in <module:ExpenseTracker>'
# ./api_spec.rb:43:in `block (2 levels) in <module:ExpenseTracker>'
# ./api_spec.rb:17:in `block in <module:ExpenseTracker>'
# ./api_spec.rb:7:in `<module:ExpenseTracker>'
# ./api_spec.rb:4:in `<top (required)>'

Finished in 0.00054 seconds (files took 0.37688 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples

i have looked at the example in the book vs what i wrote, and i dont see a difference, am i misisng somehting?

Myron-profile-img_pragsmall
18 Dec 2017, 18:55
Myron Marston (15 posts)

You’ve put the code that is intended to be the content of the examples–lines like post '/expenses', JSON.generate(expense)–within the body of the example group (the context block) instead of within the body of an individual example (an it block). Looking at the code you pasted, this is happening because your it lines do not have a do/end attached to them to define the it blocks. So you are defining a couple examples with no attached body, and then putting the code that should be in the example body in the example group body instead.

If you add do on the end of your it lines, and then add an appropriate end where the examples should end, it should work.

Generic-user-small
18 Dec 2017, 19:02
Denis S Dujota (13 posts)

WOW !

it’s the little things are killing me ! lol

Second set of eyes helps so much.

Thank you again!

You must be logged in to comment