litaio / lita

ChatOps for Ruby.
https://www.lita.io
MIT License
1.68k stars 179 forks source link

http.get handler not routing #198

Closed Telmo closed 4 years ago

Telmo commented 8 years ago

I am trying to create a very simple handler. I used the command lita handler health to generate the handler. the expected behavior is that of when the /healthcheck endpoint is hit is just returns "OK". the code is fairly simple and straight forward:

lita-health/lib/lita/handlers/health.rb

module Lita
  module Handlers
    class Health < Handler
      # insert handler code here
      http.get "/healtchcheck" do |request, response|
          response.body << "OK"
      end

      Lita.register_handler(self)
    end
  end
end

And the specs are also rather basic:

spec/lita/handlers/health_spec.rb

require "spec_helper"

describe Lita::Handlers::Health, lita_handler: true do
  it { is_expected.to route_http(:get, "/healthcheck") }

describe "#healthcheck" do
 it "writes 'OK' as a reply" do
  response = http.get("/healthcheck")
  expect(response.body).to eq("OK")
 end
end
end

But for some reason the endpoint is not being route even form the specs:

root@9a1456656265:/src/lita/lita-health# rspec
FF

Failures:

  1) Lita::Handlers::Health should route http :get and "/healthcheck"
     Failure/Error: it { is_expected.to route_http(:get, "/healthcheck") }
       expected #<Lita::Handlers::Health:0x005602a845c468 @robot=#<Lita::Robot:0x005602a84c7768 @registry=#<Lita::Reg...redis://127.0.0.1:6379/0>, @warning=true, @deprecations=false>, @warning=true, @deprecations=false>> to route http :get and "/healthcheck"
     # ./spec/lita/handlers/health_spec.rb:4:in `block (2 levels) in <top (required)>'

  2) Lita::Handlers::Health#healthcheck writes 'OK' as a reply
     Failure/Error: expect(response.body).to eq("OK")

       expected: "OK"
            got: "Your request couldn't be found"

       (compared using ==)
     # ./spec/lita/handlers/health_spec.rb:9:in `block (3 levels) in <top (required)>'

Finished in 0.07995 seconds (files took 0.49442 seconds to load)
2 examples, 2 failures

Failed examples:

rspec ./spec/lita/handlers/health_spec.rb:4 # Lita::Handlers::Health should route http :get and "/healthcheck"
rspec ./spec/lita/handlers/health_spec.rb:7 # Lita::Handlers::Health#healthcheck writes 'OK' as a reply

I've followed the documentation for created the HTTPRoutes and to test them https://docs.lita.io/plugin-authoring/testing/#testing-handlers https://docs.lita.io/plugin-authoring/testing/#testing-routes https://docs.lita.io/plugin-authoring/testing/#testing-behavior

I am using lite 4.7.0

root@9a1456656265:/src/lita# bundle list
Gems included by the bundle:
  * bundler (1.12.5)
  * faraday (0.9.2)
  * http_router (0.11.2)
  * i18n (0.7.0)
  * ice_nine (0.11.2)
  * lita (4.7.0)
  * multi_json (1.12.1)
  * multipart-post (2.0.0)
  * puma (3.6.0)
  * rack (2.0.1)
  * rb-readline (0.5.3)
  * redis (3.3.1)
  * redis-namespace (1.5.2)
  * thor (0.19.1)
  * url_mount (0.2.1)
root@9a1456656265:/src/

the ruby version is 2.3.1p112

root@9a1456656265:/src/lita# ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
root@9a1456656265:/src/lita#

Am I missing something? any help would be appreciated.

jimmycuadra commented 8 years ago

From the information you've shared, I am not seeing an obvious problem. I tried creating a handler with the exact same code and the tests pass for me. >_<

jwoffindin commented 8 years ago

Your example handler code had:

http.get "/healtchcheck" do |request, response|

did you mean

http.get "/healthcheck" do |request, response|

?