Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix specs #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
source 'https://rubygems.org/'

gem 'byebug'

gemspec
10 changes: 5 additions & 5 deletions lib/rack/logstash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ def exception_log_entry(env, ex)
req = Rack::Request.new(env)

common_entry_fields(env).tap do |e|
e['message'] = "#{req.ip} " +
"#{req.request_method} " +
"#{req.path_info_and_query_string} " +
"#{req.server_protocol} " +
"=> #{ex.message} (#{ex.class})"
e['message'] = "#{req.ip} " +
"#{req.request_method} " +
"#{req.path_info_and_query_string} " +
"#{req.server_protocol} " +
"=> #{ex.message} (#{ex.class})"

e['exception'] = {
'class' => ex.class,
Expand Down
30 changes: 12 additions & 18 deletions spec/rack_logstash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,22 @@
# This... is evil
let(:log_entry) { {} }

before :each do
expect(Rack::Logstash::Transport).
to receive(:new).
with('tcp://logstash:5151').
before do
expect(Rack::Logstash::Transport).to receive(:new).with('tcp://logstash:5151').
and_return(mock_transport)

expect(mock_transport).to receive(:send) do |s|
log_entry.replace(JSON.parse(s))
log_entry.replace(s)
end

allow(Socket).
to receive(:gethostname).
and_return("server.example.com")
allow(Socket).to receive(:gethostname).and_return("server.example.com")
end

let(:response) { [200, [], ["OK"]] }

context "a simple request" do
before :each do
expect(Time).
to receive(:now).
with(no_args).
before do
expect(Time).to receive(:now).with(no_args).
and_return(
Time.at(1234567890).utc,
Time.at(1234567890.01).utc
Expand Down Expand Up @@ -77,7 +71,7 @@
end

it "logs the timestamp" do
expect(log_entry['timestamp']).to eq(Time.now.strftime("13/Feb/2009:23:31:30 +0000"))
expect(log_entry['timestamp']).to eq(Time.now.strftime("2009-02-13T23:31:30.000Z"))
end

it "logs the verb" do
Expand Down Expand Up @@ -153,13 +147,13 @@
end
end

context "with tags" do
context "with service" do
let(:app) do
url = logstash_url
res = response

Rack::Builder.new do
use Rack::Logstash, url, :tags => ["foo", "bar"]
use Rack::Logstash, url, service: 'simple_service'

run proc { |env| res }
end
Expand All @@ -173,8 +167,8 @@
expect(log_entry).to_not be_empty
end

it "sends the tags" do
expect(log_entry['tags']).to eq(["foo", "bar"])
it "sends the service" do
expect(log_entry['service']).to eq('simple_service')
end
end

Expand Down Expand Up @@ -212,7 +206,7 @@
end

it "sends an exception class" do
expect(log_entry['exception']['class']).to eq("RuntimeError")
expect(log_entry['exception']['class']).to eq(RuntimeError)
end

it "sends an exception message" do
Expand Down
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
Bundler.setup(:default, :development)
require 'rspec/core'
require 'rspec/mocks'
require 'byebug'

RSpec.configure do |config|
config.fail_fast = true
# config.full_backtrace = true
config.full_backtrace = true

config.expect_with :rspec do |c|
c.syntax = :expect
Expand Down