spec/spec_helper.rb in moo_moo-0.1.1 vs spec/spec_helper.rb in moo_moo-0.2.0

- old
+ new

@@ -1,26 +1,20 @@ require 'rspec' require 'moo_moo' +require 'webmock/rspec' require 'vcr' require 'extlib' -MooMoo.configure do |config| - config.host = ENV['OPENSRS_TEST_URL'] - config.key = ENV['OPENSRS_TEST_KEY'] - config.user = ENV['OPENSRS_TEST_USER'] - config.pass = ENV['OPENSRS_TEST_PASS'] -end - VCR.config do |c| c.cassette_library_dir = 'spec/vcr_cassettes' - c.stub_with :fakeweb + c.stub_with :webmock - c.default_cassette_options = {:record => :new_episodes, :match_requests_on => [:uri]} + c.default_cassette_options = {:record => :none, :match_requests_on => [:uri]} end def requires_attr(attr, &block) - expect { block.call }.to raise_error(MooMoo::MooMooArgumentError, /Missing required parameter: #{attr}/i) + expect { block.call }.to raise_error(MooMoo::ArgumentError, /Missing required parameter: #{attr}/i) end def live_test? !ENV['OPENSRS_REAL'].nil? end @@ -57,24 +51,22 @@ end RSpec.configure do |c| c.extend VCR::RSpec::Macros c.before(:each) do - if live_test? - MooMoo.configure do |config| - config.host = ENV['OPENSRS_TEST_URL'] - config.key = ENV['OPENSRS_TEST_KEY'] - config.user = ENV['OPENSRS_TEST_USER'] - config.pass = ENV['OPENSRS_TEST_PASS'] + MooMoo.configure do |config| + if live_test? + config.host = ENV['OPENSRS_TEST_URL'] if ENV['OPENSRS_TEST_URL'] + config.key = ENV['OPENSRS_TEST_KEY'] || raise(ArgumentError, "OPENSRS_TEST_KEY is required") + config.user = ENV['OPENSRS_TEST_USER'] || raise(ArgumentError, "OPENSRS_TEST_USER is required") + config.pass = ENV['OPENSRS_TEST_PASS'] || raise(ArgumentError, "OPENSRS_TEST_PASS is required") + else + config.host = "testhost.com" + config.key = "testkey" + config.user = "testuser" + config.pass = "testpass" end - else - MooMoo.configure do |config| - config.host = 'server.com' - config.key = '123key' - config.user = 'opensrs_user' - config.pass = 'password' - end end end end RSpec::Matchers.define :have_attr_accessor do |attribute| @@ -84,5 +76,25 @@ description do "have attr_accessor :#{attribute}" end end + +RSpec::Matchers.define(:have_registered_service) do |*args| + method_name = args[0] + object_name = args[1] + action_name = args[2] || method_name + + match do |object| + parameters = {:the => :params, :cookie => "thecookie"} + object.should_receive(:run_command). + with(action_name, object_name, parameters, "thecookie"). + and_return("theresult") + + + object.send(method_name, parameters) == "theresult" + end + + description do + "have registered service :#{method_name} delegating to action :#{action_name} and object :#{object_name}" + end +end \ No newline at end of file