Permalink
Browse files

Add file-related Cucumber steps

  • Loading branch information...
1 parent c47e143 commit 830d2ca651dc7d6955fef98b008e71fde0a5cf6a @bleonard bleonard committed with laserlemon Aug 23, 2011
Showing with 108 additions and 11 deletions.
  1. +89 −0 features/files.feature
  2. +2 −0 features/support/env.rb
  3. +1 −11 features/support/files/project/version/two.json
  4. +16 −0 lib/json_spec/cucumber.rb
View
@@ -0,0 +1,89 @@
+Feature: Files
+ Scenario: Equivalence from a file
+ Given the JSON is:
+ """
+ {
+ "array": [
+ "json",
+ "spec"
+ ],
+ "false": false,
+ "float": 10.0,
+ "hash": {
+ "json": "spec"
+ },
+ "created_at": "2011-07-08 02:27:34",
+ "empty_array": [
+
+ ],
+ "empty_hash": {
+ },
+ "id": 1,
+ "integer": 10,
+ "negative": -10,
+ "null": null,
+ "string": "json_spec",
+ "true": true,
+ "updated_at": "2011-07-08 02:28:50"
+ }
+ """
+ When I get the JSON
+ Then the JSON should be file "two.json"
+
+ Scenario: Inequivalence from a file
+ Given the JSON is:
+ """
+ {
+ "string": "json_spec",
+ "true": true,
+ "updated_at": "2011-07-08 02:28:50"
+ }
+ """
+ When I get the JSON
+ Then the JSON should not be file "two.json"
+
+
+ Scenario: Inclusion from a file
+ Given the JSON is:
+ """
+ {
+ "array": [
+ "json",
+ "spec"
+ ],
+ "created_at": "2011-07-08 02:27:34",
+ "empty_array": [
+
+ ],
+ "empty_hash": {
+ },
+ "false": false,
+ "float": 10.0,
+ "hash": {
+ "json": "spec"
+ }
+ }
+ """
+ When I get the JSON
+ Then the JSON should include file "project/version/two.json"
+
+ Scenario: Exclusion from a file
+ Given the JSON is:
+ """
+ {
+ "array": [
+ "json",
+ "spec"
+ ],
+ "created_at": "2011-07-08 02:27:34",
+ "empty_array": [
+
+ ],
+ "empty_hash": {
+ },
+ "false": false,
+ "float": 10.0
+ }
+ """
+ When I get the JSON
+ Then the JSON should not include file "project/version/two.json"
View
@@ -1,6 +1,8 @@
$: << File.expand_path("../../../lib", __FILE__)
require "json_spec/cucumber"
+JsonSpec.directory = File.expand_path("../files", __FILE__)
+
def last_json
@last_json.to_s
end
@@ -1,13 +1,3 @@
{
- "array": [
-
- ],
- "false": false,
- "float": 10.0,
- "hash": {
- },
- "integer": 10,
- "null": null,
- "string": "json_spec",
- "true": true
+ "json": "spec"
}
View
@@ -18,6 +18,14 @@
end
end
+Then /^the (?:JSON|json)(?: response)?(?: at "(.*)")? should( not)? be file "(.+)"$/ do |path, negative, file_path|
+ if negative
+ last_json.should_not be_json_eql.to_file(file_path).at_path(path)
+ else
+ last_json.should be_json_eql.to_file(file_path).at_path(path)
+ end
+end
+
Then /^the (?:JSON|json)(?: response)?(?: at "(.*)")? should( not)? be (".*"|\-?\d+(?:\.\d+)?(?:[eE][\+\-]?\d+)?|\[.*\]|%?\{.*\}|true|false|null)$/ do |path, negative, value|
if negative
last_json.should_not be_json_eql(JsonSpec.remember(value)).at_path(path)
@@ -34,6 +42,14 @@
end
end
+Then /^the (?:JSON|json)(?: response)?(?: at "(.*)")? should( not)? include file "(.+)"$/ do |path, negative, file_path|
+ if negative
+ last_json.should_not include_json.from_file(file_path).at_path(path)
+ else
+ last_json.should include_json.from_file(file_path).at_path(path)
+ end
+end
+
Then /^the (?:JSON|json)(?: response)?(?: at "(.*)")? should( not)? include (".*"|\-?\d+(?:\.\d+)?(?:[eE][\+\-]?\d+)?|\[.*\]|%?\{.*\}|true|false|null)$/ do |path, negative, value|
if negative
last_json.should_not include_json(JsonSpec.remember(value)).at_path(path)

0 comments on commit 830d2ca

Please sign in to comment.