<commit_before>require 'spec_helper'

describe "Exchange::ExternalAPI::CurrencyBot" do
  before(:all) do
    Exchange::Configuration.cache = false
  end
  describe "updating rates" do
    subject { Exchange::ExternalAPI::CurrencyBot.new }
    before(:each) do
      mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'))
    end
    it "should call the api and yield a block with the result" do
      subject.update
      subject.base.should == 'USD'
    end
    it "should set a unix timestamp from the api file" do
      subject.update
      subject.timestamp.should == 1327748496
    end
  end
  describe "conversion" do
    subject { Exchange::ExternalAPI::CurrencyBot.new }
    before(:each) do
      mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'))
    end
    it "should convert right" do
      subject.convert(80, 'eur', 'usd').round.should == 105.76
    end
    it "should convert negative numbers right" do
      subject.convert(-70, 'chf', 'usd').should == -76.71
    end
    it "should convert when given symbols" do
      subject.convert(70, :sek, :usd).should == 10.38
    end
  end
  describe "historic conversion" do
    subject { Exchange::ExternalAPI::CurrencyBot.new }
    it "should convert and be able to use history" do
      mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/historical/2011-09-09.json", fixture('api_responses/example_json_api.json'))
      subject.convert(70, 'eur', 'usd', :at => Time.gm(2011,9,9)).round.should == 92.54
    end
    it "should convert negative numbers right" do
      mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/historical/2011-09-09.json", fixture('api_responses/example_json_api.json'))
      subject.convert(-70, 'chf', 'usd', :at => Time.gm(2011,9,9)).should == -76.71<commit_msg>! specs for currency bot<commit_after>require 'spec_helper'

describe "Exchange::ExternalAPI::CurrencyBot" do
  before(:all) do
    Exchange::Configuration.cache = false
  end
  describe "updating rates" do
    subject { Exchange::ExternalAPI::CurrencyBot.new }
    before(:each) do
      mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'))
    end
    it "should call the api and yield a block with the result" do
      subject.update
      subject.base.should == 'USD'
    end
    it "should set a unix timestamp from the api file" do
      subject.update
      subject.timestamp.should == 1327748496
    end
  end
  describe "conversion" do
    subject { Exchange::ExternalAPI::CurrencyBot.new }
    before(:each) do
      mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'))
    end
    it "should convert right" do
      subject.convert(80, 'eur', 'usd').round(2).should == 105.76
    end
    it "should convert negative numbers right" do
      subject.convert(-70, 'chf', 'usd').should == -76.71
    end
    it "should convert when given symbols" do
      subject.convert(70, :sek, :usd).should == 10.38
    end
  end
  describe "historic conversion" do
    subject { Exchange::ExternalAPI::CurrencyBot.new }
    it "should convert and be able to use history" do
      mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/historical/2011-09-09.json", fixture('api_responses/example_json_api.json'))
      subject.convert(70, 'eur', 'usd', :at => Time.gm(2011,9,9)).round(2).should == 92.54
    end
    it "should convert negative numbers right" do
      mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/historical/2011-09-09.json", fixture('api_responses/example_json_api.json'))
      subject.convert(-70, 'chf', 'usd', :at => Time.gm(2011,9,9)).should == -76.71
{'fraction_non_alphanumeric': 0.13457135588908675, 'fraction_numerical': 0.03561434749427626, 'mean_word_length': 3.6313309776207303, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3863077', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1220, 'n_words': 281}