<commit_before>require 'helper'
require 'stringio'

describe Nasreddin::APIServerResource do

    let(:resp) { [200,{}, StringIO.new('bar') ] }
    let(:resource_stubbed) { Nasreddin::APIServerResource.new('prefix','foo',stub()) }
    let(:heartbeat_msg) { {'__heartbeat__' => true } }
    let(:msg) { {'resource' => 'foo' } }

    it "should have a DEFAULT_ENV hash" do
      Nasreddin::APIServerResource::DEFAULT_ENV.class.should.equal Hash
    end

    it ".process_incoming_message should return a status, headers and resp" do
        app = stub(:call => resp)
        resource = Nasreddin::APIServerResource.new("prefix","foo",app)
        resource.expects(:env).returns(nil)
        result =  resource.process_incoming_message({})
        # this fails, I suppose its a shoulda bug
        # result.should.equal [200,{},"bar"]
        result[0].should.equal 200
        result[2].should.equal "bar"
    end

    it "should connect to hornetq only once" do
        TorqueBox::Messaging::Queue.expects(:start).once.returns(stub())
        2.times { resource_stubbed.queue }
    end

    it "build an env Hash" do
        msg= {
            secure: true,
            method: 'post',
            params:  { key: 'value'},
            id: 123,
            path: 'path',
            other: 'value'
        }
        env= resource_stubbed.env(msg)
        env['rack.url_scheme'].should.equal 'https'
        env['REQUEST_METHOD'].should.equal 'POST'
        env['QUERY_STRING'].should.equal 'key=value'
        env['PATH_INFO'].should.equal 'prefix/foo/123/path'
        env[:other].should.equal 'value'

    end

    it "should handle heartbeat messages" do
        resource_stubbed.is_heartbeat?(heartbeat_msg).should.equal true
        resource_stubbed.is_heartbeat?(msg).should.not.equal true
    end
end

describe "its a rack application" do
  extend Rack::Test::Methods

  def app
    MockServer.new
  end

  it "is working" do
    get '/'
    last_response.should.be.ok
    last_response.body.should.equal 'body'
  end
end<commit_msg>fix specs<commit_after>require 'helper'
require 'stringio'

describe Nasreddin::APIServerResource do

    let(:resp) { [200,{}, StringIO.new('bar') ] }
    let(:resource_stubbed) { Nasreddin::APIServerResource.new('prefix','foo',stub()) }
    let(:heartbeat_msg) { {:params => {'__heartbeat__' => true } } }
    let(:msg) { {'resource' => 'foo' } }

    it "should have a DEFAULT_ENV hash" do
      Nasreddin::APIServerResource::DEFAULT_ENV.class.should.equal Hash
    end

    it ".process_incoming_message should return a status, headers and resp" do
        app = stub(:call => resp)
        resource = Nasreddin::APIServerResource.new("prefix","foo",app)
        resource.expects(:env).returns(nil)
        result =  resource.process_incoming_message({})
        # this fails, I suppose its a shoulda bug
        # result.should.equal [200,{},"bar"]
        result[0].should.equal 200
        result[2].should.equal "bar"
    end

    it "should connect to hornetq only once" do
        TorqueBox::Messaging::Queue.expects(:start).once.returns(stub())
        2.times { resource_stubbed.queue }
    end

    it "build an env Hash" do
        msg= {
            secure: true,
            method: 'post',
            params:  { key: 'value'},
            id: 123,
            path: 'path',
            other: 'value'
        }
        env= resource_stubbed.env(msg)
        env['rack.url_scheme'].should.equal 'https'
        env['REQUEST_METHOD'].should.equal 'POST'
        env['QUERY_STRING'].should.equal 'key=value'
        env['PATH_INFO'].should.equal 'prefix/foo/123/path'
        env[:other].should.equal 'value'

    end

    it "should handle heartbeat messages" do
        resource_stubbed.is_heartbeat?(heartbeat_msg).should.equal true
        resource_stubbed.is_heartbeat?(msg).should.not.equal true
    end
end

describe "its a rack application" do
  extend Rack::Test::Methods
  let(:resp) { [200,{}, StringIO.new('bar') ] }

  def app
    TorqueBox::Messaging::Queue.expects(:start).once.returns(stub(:call => resp))
    MockServer.new  resources: %w| foo |
  end

  it "is working" do
    get '/'
    last_response.should.be.ok
    last_response.body.should.equal 'body'
  end
end
{'fraction_non_alphanumeric': 0.13443396226415094, 'fraction_numerical': 0.00919811320754717, 'mean_word_length': 2.7697777777777777, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7537513', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1326, 'n_words': 289}