0

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!

1 Answer 1

1
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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.