Sha256: 2d99700ed3b3072e4c1339a0c5971a295270a4548ea7aadc7cac32b1dfa839c5

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

module FileHelpers
  ORIGINAL_SCHEMA_ROOT = JsonMatchers.schema_root

  def create_schema(name, json)
    File.open("#{schema_root}/#{name}.json", "w") do |file|
      case json
      when NilClass, String
        file.write(json.to_s)
      else
        file.write(json.to_json)
      end
    end
  end

  def response_for(json)
    response_body = case json
                    when String, NilClass
                      json.to_s
                    else
                      json.to_json
                    end
    double(body: response_body)
  end

  def schema_root
    JsonMatchers.schema_root
  end
end

RSpec.configure do |config|
  config.include FileHelpers

  config.before(:each) { JSON::Validator.clear_cache }

  config.around do |example|
    JsonMatchers.schema_root = File.join(Dir.pwd, "spec", "fixtures", "schemas")
    FileUtils.mkdir_p(JsonMatchers.schema_root)

    example.run

    FileUtils.rm_rf(JsonMatchers.schema_root)
    JsonMatchers.schema_root = FileHelpers::ORIGINAL_SCHEMA_ROOT
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
json_matchers-0.6.1 spec/support/file_helpers.rb
json_matchers-0.6.0 spec/support/file_helpers.rb
json_matchers-0.5.1 spec/support/file_helpers.rb