Sha256: d1eb5617bbe9b1dcec243853c7eb767653aaedd61107f3293ce7bca8e6ff96e9

Contents?: true

Size: 970 Bytes

Versions: 3

Compression:

Stored size: 970 Bytes

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.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 & 2 rubygems

Version Path
json_matchers-0.5.0 spec/support/file_helpers.rb
json_matchers-0.4.0 spec/support/file_helpers.rb
json-matchers-0.3.1 spec/support/file_helpers.rb