Sha256: 33459e9ed61fc9a884dd94422398b95cc3c4ac6039392fdd64d64250ff412e9b

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require 'formhub_ruby'
require 'spec_helper'
require 'yaml'

describe FormhubRuby::ApiConnector do

  before :each do
    credentials = YAML.load_file('spec/fixtures/test_credentials.yml')
    FormhubRuby.configure do |config|
      config.username = credentials['username']
      config.password = credentials['password']
    end
  end

  it 'successfully connects to the FormHub API and retrieve JSON Data' do
    VCR.use_cassette 'successful_connection' do 
      connection = FormhubRuby::ApiConnector.new(formname: 'survey')
      connection.fetch
      connection.data.should be_a_kind_of(Array)
      connection.data[0].should be_a_kind_of(Object)
    end
  end

  it "displays appropriate message if the JSON data is not successfully retrieved" do
      stub_request(:any, "http://formhub.org/#{FormhubRuby.configuration.username}/forms/survey/api").to_return(:body => "NO JSON HERE")
      connection = FormhubRuby::ApiConnector.new(formname: 'fake')
      expect {connection.fetch}.to raise_error("API connection error")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
formhub_ruby-0.0.1 spec/api_connectior_spec.rb