features/json_processing.feature in jr-cli-0.2.0 vs features/json_processing.feature in jr-cli-0.3.0
- old
+ new
@@ -1,9 +1,31 @@
Feature: JSON processing
jr is jq like JSON processor for Rubyist
+ Scenario: Indent JSON
+ Given a file named "input.json" with:
+ """
+ {"name":"foo"}
+ {"name":"bar"}
+ {"name":"baz"}
+ """
+ When I run `cat input.json | jr` in bash
+ Then the output should contain exactly:
+ """
+ {
+ "name": "foo"
+ }
+ {
+ "name": "bar"
+ }
+ {
+ "name": "baz"
+ }
+
+ """
+
Scenario: Filter single JSON of Object
Given a file named "input.json" with:
"""
{"foo":"bar"}
"""
@@ -241,7 +263,90 @@
Then the output should contain exactly:
"""
foo
bar
baz
+
+ """
+
+ Scenario: Read each line as string using --raw-input option
+ Given a file named "input.json" with:
+ """
+ foo
+ bar
+ baz
+
+ """
+ When I run `jr --raw-input 'self' input.json`
+ Then the output should contain exactly:
+ """
+ "foo"
+ "bar"
+ "baz"
+
+ """
+
+ Scenario: Read filter from file using -f option.
+ Given a file named "input.json" with:
+ """
+ {"ua":"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"}
+ {"ua":"Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3"}
+ {"ua":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:21.0) Gecko/20100101 Firefox/21.0"}
+
+ """
+ And a file named "filter.rb" with:
+ """
+ require 'woothee'
+
+ select { |j| not Woothee.is_crawler(j.ua) }
+ .map { |j| Woothee.parse(j.ua).name }
+ """
+ When I run `jr -f filter.rb input.json`
+ Then the output should contain exactly:
+ """
+ "Safari"
+ "Firefox"
+
+ """
+
+ Scenario: Read filter from file using --from-file option.
+ Given a file named "input.json" with:
+ """
+ {"ua":"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"}
+ {"ua":"Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3"}
+ {"ua":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:21.0) Gecko/20100101 Firefox/21.0"}
+
+ """
+ And a file named "filter.rb" with:
+ """
+ require 'woothee'
+
+ select { |j| not Woothee.is_crawler(j.ua) }
+ .map { |j| Woothee.parse(j.ua).name }
+ """
+ When I run `jr --from-file filter.rb input.json`
+ Then the output should contain exactly:
+ """
+ "Safari"
+ "Firefox"
+
+ """
+
+ Scenario: Read no file and build JSONs from scratch using --null-input option.
+ When I run `jr --null-input '1.upto(3).map{ |n| "%02d" % n }'`
+ Then the output should contain exactly:
+ """
+ "01"
+ "02"
+ "03"
+
+ """
+
+ Scenario: Read no file and build JSONs from scratch using -n option.
+ When I run `jr -n '1.upto(3).map{ |n| "%02d" % n }'`
+ Then the output should contain exactly:
+ """
+ "01"
+ "02"
+ "03"
"""