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

feature: Use JSON.pretty_generate insted of to_json #39

Merged
merged 1 commit into from
Jun 12, 2023
Merged
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: 1 addition & 1 deletion mrblib/rf/00filter/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def decorate(val)
if raw? && val.instance_of?(String)
val
else
JSON.pretty_generate(val)
val.to_json
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions mrblib/rf/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,11 @@ def add_features_to_hash
key?(sym.to_s) || super
end
end

def add_features_to_json
Object.define_method(:to_json) do
JSON.pretty_generate(self)
end
end
end
end
1 change: 1 addition & 0 deletions mrblib/rf/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def add_features
Rf.add_features_to_integer
Rf.add_features_to_float
Rf.add_features_to_hash
Rf.add_features_to_json
end

def do_action
Expand Down
10 changes: 10 additions & 0 deletions spec/feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,14 @@
it { expect(last_command_started).to have_output output_string_eq output }
end
end

describe 'to_json' do
let(:input) { load_fixture('json/hash.json') }
let(:output) do
before { run_rf("-j -q 'puts _.to_json'", input) }

it { expect(last_command_started).to be_successfully_executed }
it { expect(last_command_started).to have_output output_string_eq output }
end
end
end