Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

different parameter values for different examples #187

Closed
jogaco opened this issue Dec 15, 2014 · 1 comment
Closed

different parameter values for different examples #187

jogaco opened this issue Dec 15, 2014 · 1 comment

Comments

@jogaco
Copy link

jogaco commented Dec 15, 2014

How is it possible to have different parameters values for different examples within the same method? Or is is possible at all?

put "/orders/:id" do
    let(:id) { order.id }

    example_request "Put an order" do
      expect(status).to eq 200
    end

    example "Get an inexistent order" do
      let(:id) { -1 }
      do_request
      expect(status).to eq 422
    end
  end

=>  NoMethodError:
       undefined method `let' for  #<RSpec::ExampleGroups::
@oestrich
Copy link
Contributor

For the specific error, let is only available in the example group context.

put "/orders/:id" do
  let(:id) { order.id }

  example_request "Put an order" do
    expect(status).to eq 200
  end

  context "order does not exist" do
    let(:id) { -1 }
    example "Get an inexistent order" do
      do_request
      expect(status).to eq 422
    end
  end
end

You can also send in an extra hash to do_request that will override that :id key.

put "/orders/:id" do
  let(:id) { order.id }

  example_request "Put an order" do
    expect(status).to eq 200
  end

  context "order does not exist" do
    example "Get an inexistent order" do
      do_request(:id => -1)
      expect(status).to eq 422
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants