BC00
BC00

Reputation: 1639

Testing Json argument with rspec

I am new to rspec and wanted to ask how one would go about testing the following.

I have an import method that takes in a json feed and my goal is to parse and save certain data based on certain conditions.

for example:

def self.import(json_feed)
  #save certain pieces of data
end

I was wondering what the best way to simulate the json feed is? Should I be creating a json object and saving it into a variable and then passing that in? or are there better conventions for something like this.

Thank You!

Upvotes: 0

Views: 123

Answers (1)

Mori
Mori

Reputation: 27789

class Foo
  class << self
    attr_reader :imported_json
  end

  self.import(json_feed)
    @imported_json = json_feed
  end
end

describe Foo do
  specify 'self.import' do
     some_json = {some: :json}.to_json
     Foo.import some_json
     Foo.imported_json.should == some_json
  end
end

Upvotes: 1

Related Questions