gui12344455
gui12344455

Reputation: 23

How to use send method to post, get, update route?

I'm trying to DRY some request specs. I need to pass to a shared example the following params:

method, action, params

shared_example:

shared_context "blah" do |method, action, params|
  let(:url_path) { send("api_cars_path") }
end

How can I execute a route with send using the method that is being passed as parameter ? Something like this:

send(:get, "api_cars_path")

So I can can pass :get, :post, etc dynamically.

Upvotes: 0

Views: 71

Answers (1)

Daniel Westendorf
Daniel Westendorf

Reputation: 3465

The route api_cars_path is really a method which returns a string like /api/cars. So you need to invoke the route helper and then pass it to the get method as the first argument.

send(:get, send(:api_cars_path))

Upvotes: 1

Related Questions