spec/spec_helper.rb in amee-data-abstraction-1.2.0 vs spec/spec_helper.rb in amee-data-abstraction-1.3.0
- old
+ new
@@ -1,23 +1,40 @@
require 'rubygems'
require 'spec'
require 'rspec_spinner'
require 'flexmock'
-$:.unshift(File.dirname(__FILE__) + '/../lib')
require 'amee'
+
+$:.unshift(File.dirname(__FILE__) + '/../lib')
require 'amee-data-abstraction'
+# Fake up Rails.root to be fixtures directory
+class Rails
+ def self.root
+ File.dirname(__FILE__) + '/fixtures'
+ end
+ def self.logger
+ nil
+ end
+end
+
Spec::Runner.configure do |config|
config.mock_with :flexmock
+ config.after(:each) do
+ delete_lock_files
+ end
end
-AMEE::DataAbstraction.connection=FlexMock.new('connection') #Global connection mock, shouldn't receive anything, as we mock the individual amee-ruby calls in the tests
-
-Dir.glob(File.dirname(__FILE__) + '/fixtures/*') do |filename|
- require filename
+def delete_lock_files
+ config_dir = Dir.new("#{Rails.root}/config/calculations")
+ config_dir.each do |file|
+ File.delete("#{config_dir.path}/#{file}") if file =~ /lock/
+ end
end
+AMEE::DataAbstraction.connection=FlexMock.new('connection') #Global connection mock, shouldn't receive anything, as we mock the individual amee-ruby calls in the tests
+
include AMEE::DataAbstraction
class AMEEMocker
def initialize(test,options)
@path=options[:path]
@@ -79,10 +96,25 @@
and_return(test.flexmock(:choices=>choices,:selections=>Hash[selections],
:data_item_uid=>dataitemuid))
return self
end
+ # This represents the skipping of drill choices which occur on an AMEE drill
+ # down when only one choice exists for a given drill - it skips to the next,
+ # offering the next set of choices or a uid. In these cases, the skipped drill
+ # is set as an automatic selection
+ def drill_with_skip(skipped_selections=[])
+ test.flexmock(AMEE::Data::DrillDown).
+ should_receive(:get).
+ with(connection,
+ "/data/#{path}/drill?#{selections.map{|k,v|"#{k}=#{v}"}.join('&')}").
+ at_least.once.
+ and_return(test.flexmock(:choices=>choices,:selections=>Hash[selections].merge(skipped_selections),
+ :data_item_uid=>dataitemuid))
+ return self
+ end
+
def profile_list
test.flexmock(AMEE::Profile::ProfileList).should_receive(:new).
with(connection).at_least.once.
and_return(test.flexmock(:first=>test.flexmock(:uid=>:someprofileuid)))
return self
@@ -249,10 +281,10 @@
end
def update
test.flexmock(AMEE::Profile::Item).should_receive(:update).
with(connection,pipath,
- {:get_item=>false}.merge(existing).merge(params)).
+ {:get_item=>true}.merge(existing).merge(params)).
at_least.once
return self
end
end
\ No newline at end of file