api - Is there a Ruby WebMock equivalent for the Lua language? -


i have lua module i'm writing making requests public api:

 -- users.lua  local http     = require("socket.http") local base_url = 'http://example.com' local api_key  = "secret" local users    = {}  function users.info(user_id)   local request_url = base_url .. '/users/' .. user_id .. "?api_key=" .. api_key   print("requesting " .. request_url)   local response = http.request(request_url)   print("response " .. response)   return response end  return users 

this works, i'd use tdd finish writing entire api wrapper.

i have spec (using busted framework) works, makes actual request api:

 -- spec/users_spec.lua   package.path = "../?.lua;" .. package.path  describe("users", function()   it("should fetch users info", function()     local users = require("users")     local s = spy.on(users, "info")     users.info("chip0db4")     assert.spy(users.info).was_called_with("chip0db4")   end) end) 

how mock out, how webmock works in ruby, actual endpoint not contacted? solution doesn't need specific busted framework, btw.

after receiving excellent feedback https://github.com/tannerrogalsky, shown here https://gist.github.com/tannerrogalsky/b56bc886811f8f0a9d2a, decided write own mocking library http requests: https://github.com/chip/webmock. it's in it's stages, it's @ least start. i'd grateful contributions repo or suggestion on other approaches or lua modules available.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -