I'm trying to refactor some common code used in a bunch of requests specs 
into a macro, but every way I've tried so far ends in an error saying it 
can't find the macro method, or if it can then it can't find the `get` 
method. Can someone point me to an example of how to do this?

# spec/requests/api/api_v1.rb
describe MyApp::API_v1 do
  context "originator" do
    describe "GET /api/v1/originator/hello" do
      it_should_check_minimum_protected_api_params 
"/api/v1/originator/hello"
    end
  end
end

# spec/support/api_macros.rb
module ApiMacros
  def self.included(base)
    base.extend(GroupMethods)
  end
  
  module GroupMethods
    def it_should_check_minimum_protected_api_params(url)    
      get url
      ...
    end
  end
end

# spec/spec_helper.rb
RSpec.configure do |config|
  config.include ApiMacros, :type => :request
end

This ends in:

$ rspec spec/requests/api
/spec/support/api_macros.rb:8:in 
`it_should_check_minimum_protected_api_params': undefined method `get' for 
#<Class:0x000001036708f0> (NoMethodError)

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msg/rspec/-/5JYXNhDkcskJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to