jimson 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +6 -0
- data/VERSION +1 -1
- data/lib/jimson/server.rb +2 -1
- data/lib/jimson/server/error.rb +4 -2
- data/spec/server_spec.rb +44 -16
- metadata +2 -2
    
        data/CHANGELOG.rdoc
    CHANGED
    
    
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0. | 
| 1 | 
            +
            0.9.0
         | 
    
        data/lib/jimson/server.rb
    CHANGED
    
    | @@ -61,6 +61,7 @@ module Jimson | |
| 61 61 |  | 
| 62 62 | 
             
                  @host = opts.delete(:host) || '0.0.0.0'
         | 
| 63 63 | 
             
                  @port = opts.delete(:port) || 8999
         | 
| 64 | 
            +
                  @show_errors = opts.delete(:show_errors) || false 
         | 
| 64 65 | 
             
                  @opts = opts
         | 
| 65 66 | 
             
                end
         | 
| 66 67 |  | 
| @@ -168,7 +169,7 @@ module Jimson | |
| 168 169 | 
             
                  rescue ArgumentError
         | 
| 169 170 | 
             
                    raise Server::Error::InvalidParams.new
         | 
| 170 171 | 
             
                  rescue Exception, StandardError => e
         | 
| 171 | 
            -
                    raise Server::Error::ApplicationError.new(e)
         | 
| 172 | 
            +
                    raise Server::Error::ApplicationError.new(e, @show_errors)
         | 
| 172 173 | 
             
                end
         | 
| 173 174 |  | 
| 174 175 | 
             
                def dispatch_request(method, params)
         | 
    
        data/lib/jimson/server/error.rb
    CHANGED
    
    | @@ -47,8 +47,10 @@ module Jimson | |
| 47 47 | 
             
                  end
         | 
| 48 48 |  | 
| 49 49 | 
             
                  class ApplicationError < Error
         | 
| 50 | 
            -
                    def initialize(err)
         | 
| 51 | 
            -
                       | 
| 50 | 
            +
                    def initialize(err, show_error = false)
         | 
| 51 | 
            +
                      msg = "Server application error"
         | 
| 52 | 
            +
                      msg += ': ' + err.message + ' at ' + err.backtrace.first if show_error
         | 
| 53 | 
            +
                      super(-32099, msg)
         | 
| 52 54 | 
             
                    end
         | 
| 53 55 | 
             
                  end
         | 
| 54 56 |  | 
    
        data/spec/server_spec.rb
    CHANGED
    
    | @@ -239,23 +239,51 @@ module Jimson | |
| 239 239 | 
             
                  end
         | 
| 240 240 |  | 
| 241 241 | 
             
                  describe "receiving a call for ugly method" do
         | 
| 242 | 
            -
                     | 
| 243 | 
            -
                       | 
| 244 | 
            -
             | 
| 245 | 
            -
             | 
| 246 | 
            -
             | 
| 247 | 
            -
             | 
| 248 | 
            -
             | 
| 242 | 
            +
                    context "by default" do
         | 
| 243 | 
            +
                      it "returns only global error without stack trace" do
         | 
| 244 | 
            +
                        req = {
         | 
| 245 | 
            +
                                'jsonrpc' => '2.0',
         | 
| 246 | 
            +
                                'method'  => 'ugly_method',
         | 
| 247 | 
            +
                                'id'      => 1
         | 
| 248 | 
            +
                              }
         | 
| 249 | 
            +
                        post_json(req)
         | 
| 249 250 |  | 
| 250 | 
            -
             | 
| 251 | 
            -
             | 
| 252 | 
            -
             | 
| 253 | 
            -
             | 
| 254 | 
            -
             | 
| 255 | 
            -
             | 
| 256 | 
            -
             | 
| 257 | 
            -
             | 
| 258 | 
            -
             | 
| 251 | 
            +
                        resp = MultiJson.decode(last_response.body)
         | 
| 252 | 
            +
                        resp.should == {
         | 
| 253 | 
            +
                                          'jsonrpc' => '2.0',
         | 
| 254 | 
            +
                                          'error'   => {
         | 
| 255 | 
            +
                                                          'code' => -32099,
         | 
| 256 | 
            +
                                                          'message' => 'Server application error'
         | 
| 257 | 
            +
                                                        },
         | 
| 258 | 
            +
                                          'id'      => 1
         | 
| 259 | 
            +
                                        }
         | 
| 260 | 
            +
                      end
         | 
| 261 | 
            +
                    end
         | 
| 262 | 
            +
             | 
| 263 | 
            +
                    context "with 'show_errors' enabled" do
         | 
| 264 | 
            +
                      it "returns an error name and first line of the stack trace" do
         | 
| 265 | 
            +
                        req = {
         | 
| 266 | 
            +
                                'jsonrpc' => '2.0',
         | 
| 267 | 
            +
                                'method'  => 'ugly_method',
         | 
| 268 | 
            +
                                'id'      => 1
         | 
| 269 | 
            +
                              }
         | 
| 270 | 
            +
             | 
| 271 | 
            +
                        app = Server.new(router, :environment => "production", :show_errors => true)
         | 
| 272 | 
            +
             | 
| 273 | 
            +
                        # have to make a new Rack::Test browser since this server is different than the normal one
         | 
| 274 | 
            +
                        browser = Rack::Test::Session.new(Rack::MockSession.new(app))
         | 
| 275 | 
            +
                        browser.post '/', MultiJson.encode(req), {'Content-Type' => 'application/json'}
         | 
| 276 | 
            +
             | 
| 277 | 
            +
                        resp = MultiJson.decode(browser.last_response.body)
         | 
| 278 | 
            +
                        resp.should == {
         | 
| 279 | 
            +
                                          'jsonrpc' => '2.0',
         | 
| 280 | 
            +
                                          'error'   => {
         | 
| 281 | 
            +
                                                          'code' => -32099,
         | 
| 282 | 
            +
                                                          'message' => "Server application error: RuntimeError at /home/chris/repos/jimson/spec/server_spec.rb:40:in `ugly_method'"
         | 
| 283 | 
            +
                                                        },
         | 
| 284 | 
            +
                                          'id'      => 1
         | 
| 285 | 
            +
                                        }
         | 
| 286 | 
            +
                      end
         | 
| 259 287 | 
             
                    end
         | 
| 260 288 | 
             
                  end
         | 
| 261 289 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: jimson
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.9.0
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2012-08- | 
| 12 | 
            +
            date: 2012-08-22 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: blankslate
         |