|
1 |
| -require 'spec_helper' |
2 |
| -require 'json' |
| 1 | +require "spec_helper" |
| 2 | +require "json" |
3 | 3 |
|
4 | 4 | RSpec.describe RailsTracepointStack::LogFormatter do
|
5 | 5 | let(:trace_double) do
|
6 |
| - instance_double(RailsTracepointStack::Trace, |
7 |
| - class_name: "MyClass", |
8 |
| - method_name: :my_method, |
9 |
| - file_path: "/path/to/file.rb", |
10 |
| - line_number: 42, |
11 |
| - params: { key: 'value' }) |
| 6 | + instance_double(RailsTracepointStack::Trace, |
| 7 | + class_name: "MyClass", |
| 8 | + method_name: :my_method, |
| 9 | + file_path: "/path/to/file.rb", |
| 10 | + line_number: 42, |
| 11 | + params: {key: "value"}) |
12 | 12 | end
|
13 | 13 |
|
14 |
| - describe '.message' do |
15 |
| - context 'when format is :json' do |
| 14 | + describe ".message" do |
| 15 | + context "when format is :json" do |
16 | 16 | before do
|
17 | 17 | allow(RailsTracepointStack)
|
18 | 18 | .to receive_message_chain(:configuration, :log_format)
|
19 | 19 | .and_return(:json)
|
20 | 20 | end
|
21 | 21 |
|
22 |
| - it 'returns a JSON formatted string' do |
| 22 | + it "returns a JSON formatted string" do |
23 | 23 | expected_json = {
|
24 | 24 | class: "MyClass",
|
25 | 25 | method_name: :my_method,
|
26 | 26 | path: "/path/to/file.rb",
|
27 | 27 | line: 42,
|
28 |
| - params: { key: 'value' } |
| 28 | + params: {key: "value"} |
29 | 29 | }.to_json
|
30 | 30 |
|
31 | 31 | expect(described_class.message(trace_double)).to eq(expected_json)
|
32 | 32 | end
|
33 | 33 | end
|
34 | 34 |
|
35 |
| - context 'when format is not :json' do |
| 35 | + context "when format is not :json" do |
36 | 36 | before do
|
37 | 37 | allow(RailsTracepointStack)
|
38 |
| - .to receive_message_chain(:configuration, :log_format) |
39 |
| - .and_return(nil) |
| 38 | + .to receive_message_chain(:configuration, :log_format) |
| 39 | + .and_return(nil) |
40 | 40 | end
|
41 | 41 |
|
42 |
| - it 'returns a text formatted string' do |
| 42 | + it "returns a text formatted string" do |
43 | 43 | expected_text = "called: MyClass#my_method in /path/to/file.rb:42 with params: {:key=>\"value\"}"
|
44 | 44 | expect(described_class.message(trace_double)).to eq(expected_text)
|
45 | 45 | end
|
46 | 46 | end
|
47 | 47 | end
|
48 | 48 |
|
49 |
| - describe '.text' do |
50 |
| - it 'returns a text formatted string' do |
| 49 | + describe ".text" do |
| 50 | + it "returns a text formatted string" do |
51 | 51 | expected_text = "called: MyClass#my_method in /path/to/file.rb:42 with params: {:key=>\"value\"}"
|
52 | 52 | expect(described_class.text(trace_double)).to eq(expected_text)
|
53 | 53 | end
|
54 | 54 | end
|
55 | 55 |
|
56 |
| - describe '.json' do |
57 |
| - it 'returns a JSON formatted string' do |
| 56 | + describe ".json" do |
| 57 | + it "returns a JSON formatted string" do |
58 | 58 | expected_json = {
|
59 | 59 | class: "MyClass",
|
60 | 60 | method_name: :my_method,
|
61 | 61 | path: "/path/to/file.rb",
|
62 | 62 | line: 42,
|
63 |
| - params: { key: 'value' } |
| 63 | + params: {key: "value"} |
64 | 64 | }.to_json
|
65 | 65 |
|
66 | 66 | expect(described_class.json(trace_double)).to eq(expected_json)
|
|
0 commit comments