Skip to content
Browse files

Cleaned up spec_helper require and $ variables

  • Loading branch information...
1 parent 7c8ff41 commit b6865f95f7e381934f7631bdbb9681c113758844 @brymck committed Mar 25, 2012
View
1 .rspec
@@ -1 +1,2 @@
--color
+--require spec_helper
View
3 Rakefile
@@ -1,4 +1,5 @@
require "bundler/gem_tasks"
+require "rspec/core/rake_task"
require "rdoc/task"
require "sdoc"
@@ -8,6 +9,8 @@ Dir["tasks/**/*.rake"].each do |rake|
load File.expand_path(rake)
end
+RSpec::Core::RakeTask.new
+
RDoc::Task.new do |rdoc|
rdoc.rdoc_dir = "doc/rdoc"
rdoc.title = "Rupee Documentation"
View
11 lib/rupee/quote.rb
@@ -74,7 +74,16 @@ def get(*params)
when Net::HTTPSuccess
@source.params.each do |param, regex|
if res.body =~ regex
- @results[param] = parse($1)
+ full_text, match = $&, $1
+
+ # Special handling for <tt>:change</tt> because quote services
+ # insist on using pretty pictures instead of minus signs
+ if param == :change
+ if (Source::BLOOMBERG || Source::YAHOO) && full_text =~ /down/
+ match = "-#{match}"
+ end
+ end
+ @results[param] = parse(match)
else
@results[param] = nil
end
View
4 lib/rupee/source/bloomberg.rb
@@ -11,8 +11,8 @@ class Source
:bid => /Bid:<\/th>\n\s*<td[^>]*>([0-9.,NA-]{1,})/,
:ask => /Ask:<\/th>\n\s*<td[^>]*>([0-9.,NA-]{1,})/,
:open => /Open:<\/th>\n\s*<td[^>]*>([0-9.,NA-]{1,})/,
- :high => /Day's Range:<\/th>\n\s*<td>[0-9.,NA-]{1,} - ([0-9.,NA-]{1,})/,
- :low => /Day's Range:<\/th>\n\s*<td>([0-9.,NA-]{1,})/,
+ :high => /(?:Day(?:'s)? Range:<\/th>\n\s*<td[^>]*>[0-9.,NA-]+ - |High - Low:<\/th>\n\s*<td[^>]*>)([0-9.,NA-]+)/,
+ :low => /(?:Day(?:'s)? Range:<\/th>\n\s*<td[^>]*>|High - Low:<\/th>\n\s*<td[^>]*>[0-9.,NA-]+ - )([0-9.,NA-]+)/,
:volume => /Volume:<\/th>\n\s*<td class[^>]+>([0-9.,NA-]{1,})/,
:mkt_cap => /Market Cap[^<]+<\/th>\n\s*<td[^>]*">([0-9.,NA-]{1,})/,
:p_e => /Current P\/E[^<]+<\/th>\n\s*<td[^>]*>([0-9.,NA-]{1,})/)
View
6 lib/rupee/source/yahoo.rb
@@ -2,9 +2,9 @@ module Rupee
class Source
YAHOO = Source.new(:yahoo,
"http://finance.yahoo.com/q?s=%s",
- :price => /yfs_l84_[^>]+>([0-9,.-]+)/,
- :change => /yfs_c(?:6[34]|10)_[^>]+>(?:<img[^>]+>)\s*([0-9,.-])+/,
- :pct_chg => /yfs_p(?:4[34]|20)_[^>]+>\(([0-9,.-]+)%\)/,
+ :price => /yfs_l(?:10|84)_[^>]+>([0-9,.-]+)/,
+ :change => /yfs_c(?:6[034]|10)_[^>]+>(?:<img[^>]+>)\s*([0-9,.-]+)/,
+ :pct_chg => /yfs_p(?:4[034]|20)_[^>]+>\(([0-9,.-]+)%\)/,
:date => /<span id="yfs_market_time">.*?, (.*?20[0-9]{1,2})/,
:time => /(?:"time"|"yfnc_tabledata1")><span id="yfs_t[51]0_[^>]+>(.*?)</,
:bid => /yfs_b00_[^>]+>([0-9,.-]{1,})/,
View
2 lib/rupee/version.rb
@@ -1,4 +1,4 @@
module Rupee
# The current version
- VERSION = "0.2.9.2"
+ VERSION = "0.2.9.3"
end
View
15 rupee.gemspec
@@ -1,5 +1,5 @@
# -*- encoding: utf-8 -*-
-$:.push File.expand_path("../lib", __FILE__)
+$LOAD_PATH.push File.expand_path("../lib", __FILE__)
require "rupee/version"
Gem::Specification.new do |s|
@@ -14,20 +14,19 @@ Gem::Specification.new do |s|
financial gems and applications.
eos
- s.rubyforge_project = "rupee"
-
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- spec/**/*_spec.rb`.split("\n")
- s.executables = `git ls-files -- bin/*`.split("\n").map do |f|
- File.basename(f)
- end
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
s.extensions = "ext/rupee/extconf.rb"
s.require_paths = ["lib", "ext"]
s.add_development_dependency "bundler", "~> 1.0"
s.add_development_dependency "rspec", "~> 2.0"
s.add_development_dependency "sdoc", "~> 0.3"
s.add_development_dependency "autotest"
- s.add_development_dependency "autotest-fsevent"
- s.add_development_dependency "autotest-growl"
+
+ if RUBY_PLATFORM =~ /darwin/
+ s.add_development_dependency "autotest-fsevent"
+ s.add_development_dependency "autotest-growl"
+ end
end
View
10 spec/native/bond_spec.rb
@@ -1,10 +1,8 @@
-require File.dirname(__FILE__) + "/../spec_helper"
-
# Discrete discounting
-# new bond price = 100
-#Continous discounting
-# bond yield to maturity = 0.09
-# new bond price = 104.282
+# new bond price = 100
+# Continous discounting
+# bond yield to maturity = 0.09
+# new bond price = 104.282
describe Bond do
before :each do
View
2 spec/native/future_spec.rb
@@ -1,5 +1,3 @@
-require File.dirname(__FILE__) + "/../spec_helper"
-
describe Future do
before :each do
@tolerance = 0.001
View
2 spec/native/option_spec.rb
@@ -1,5 +1,3 @@
-require File.dirname(__FILE__) + "/../spec_helper"
-
describe Option do
describe "European option valuation" do
before :each do
View
2 spec/native/statistics_spec.rb
@@ -1,5 +1,3 @@
-require File.dirname(__FILE__) + "/../spec_helper"
-
describe Statistics do
before :each do
@tolerance = 0.0001
View
2 spec/ruby/business_day_spec.rb
@@ -1,5 +1,3 @@
-require File.dirname(__FILE__) + "/../spec_helper"
-
describe BusinessDay do
before :each do
@new_years = Date.new(2012, 1, 1)
View
2 spec/ruby/calendar_spec.rb
@@ -1,5 +1,3 @@
-require File.dirname(__FILE__) + "/../spec_helper"
-
describe Calendar do
def test_calendar(calendar, holidays)
holidays.each do |holiday|
View
2 spec/ruby/currency_spec.rb
@@ -1,6 +1,4 @@
# encoding: utf-8
-require File.dirname(__FILE__) + "/../spec_helper"
-
describe Currency do
it "should at least have the dollar, euro, pound and yen" do
Currency::USD.should_not be_nil
View
2 spec/ruby/day_count_spec.rb
@@ -1,5 +1,3 @@
-require File.dirname(__FILE__) + "/../spec_helper"
-
describe DayCount do
before :each do
@christmas = Date.new(2011, 12, 25)
View
2 spec/ruby/fixed_income_spec.rb
@@ -1,5 +1,3 @@
-require File.dirname(__FILE__) + "/../spec_helper"
-
describe FixedIncome do
it "should be able to instantiate a basic fixed income product" do
lambda { FixedIncome.new }.should_not raise_error
View
2 spec/ruby/generic_spec.rb
@@ -1,5 +1,3 @@
-require File.dirname(__FILE__) + "/../spec_helper"
-
describe "Autoloading" do
it "should produce no errors when loading all constants two levels deep" do
Rupee.constants.each do |c|
View
33 spec/ruby/quote_spec.rb
@@ -1,5 +1,3 @@
-require File.dirname(__FILE__) + "/../spec_helper"
-
describe Quote do
# Attempts to run the block and submits a pending message if a socket error
# occurs, the most common cause of which is that the user isn't connected to
@@ -44,6 +42,28 @@ def run_if_connected(&block)
@wfc.frequency -= freq_change
@wfc.next_pull.should == orig_pull - freq_change
end
+
+ it "should be able to detect negative and positive changes" do
+ run_if_connected do
+ eurusd = Quote.new("EURUSD:IND").change
+ usdeur = Quote.new("USDEUR:IND").change
+ eurusd.should be_within(0.01).of -usdeur
+ end
+ end
+ end
+
+ describe "requesting security types with special treatment in Bloomberg" do
+ it "should grab a change for indices" do
+ run_if_connected do
+ Quote.new("SPX:IND").change.should_not be_nil
+ end
+ end
+
+ it "should grab a change for ETFs" do
+ run_if_connected do
+ Quote.new("DBA").change.should_not be_nil
+ end
+ end
end
describe "specifying Google Finance as the quote service" do
@@ -68,7 +88,6 @@ def run_if_connected(&block)
end
end
end
-
end
describe "specifying Yahoo! Finance as the quote service" do
@@ -93,5 +112,13 @@ def run_if_connected(&block)
end
end
end
+
+ it "should be able to detect negative and positive changes" do
+ run_if_connected do
+ eurusd = Quote.new("EURUSD=X", :source => :yahoo).change
+ usdeur = Quote.new("USDEUR=X", :source => :yahoo).change
+ eurusd.should be_within(0.01).of -usdeur
+ end
+ end
end
end
View
2 spec/ruby/source_spec.rb
@@ -1,5 +1,3 @@
-require File.dirname(__FILE__) + "/../spec_helper"
-
describe Source do
it "should have a Bloomberg source" do
Source.find(:bloomberg).should_not be_nil
View
2 spec/spec_helper.rb
@@ -1,3 +1,3 @@
-$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
+$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
require "rupee"
include Rupee

0 comments on commit b6865f9

Please sign in to comment.
Something went wrong with that request. Please try again.