Skip to content

Commit

Permalink
Replace rspec-rails with rspec
Browse files Browse the repository at this point in the history
#39

This PR replaces `rspec-rails` with `rspec`, and removes the
`activesupport` dependency, which should make it easier to use this gem
outside of a Rails environment.

As a nice bonus, it also reduces the total number of gem dependencies
(as reported by `bundle install`) from 35 to 15.

There were only a few methods provided by ActiveSupport that were being
used, which have been replaced.
  • Loading branch information
omghax authored and seanpdoyle committed Oct 28, 2016
1 parent 1ad0b87 commit 19f9876
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
3 changes: 1 addition & 2 deletions json_matchers.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency("json-schema", "~> 2.6.0")
spec.add_dependency("activesupport", '>= 3.0.0')

spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "pry"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec-rails", ">= 2.0"
spec.add_development_dependency "rspec", ">= 2.0"
end
5 changes: 3 additions & 2 deletions lib/json_matchers.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
require "json_matchers/version"
require "json_matchers/matcher"
require "json_matchers/errors"
require "active_support/all"

module JsonMatchers
mattr_accessor :schema_root
class << self
attr_accessor :schema_root
end

self.schema_root = "#{Dir.pwd}/spec/support/api/schemas"

Expand Down
2 changes: 2 additions & 0 deletions lib/json_matchers/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def failure_message_when_negated(response)
FAIL
end

private

def pretty_json(json_string)
JSON.pretty_generate(JSON.parse(json_string.to_s))
end
Expand Down
7 changes: 6 additions & 1 deletion spec/json_matchers/match_response_schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@

def raise_formatted_error(error_message)
raise_error do |error|
expect(error.message.squish).to include(error_message)
sanitized_message = error.message.
gsub(/\A[[:space:]]+/, "").
gsub(/[[:space:]]+\z/, "").
gsub(/[[:space:]]+/, " ")

expect(sanitized_message).to include(error_message)
end
end
end
5 changes: 4 additions & 1 deletion spec/support/file_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require "fileutils"
require "json"

module FileHelpers
ORIGINAL_SCHEMA_ROOT = JsonMatchers.schema_root

Expand All @@ -7,7 +10,7 @@ def create_schema(name, json)
when NilClass, String
file.write(json.to_s)
else
file.write(json.to_json)
file.write(JSON.generate(json))
end
end
end
Expand Down

0 comments on commit 19f9876

Please sign in to comment.