cardflex-ruby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +125 -0
- data/cardflex.gemspec +14 -0
- data/lib/cardflex.rb +32 -0
- data/lib/cardflex/base_module.rb +34 -0
- data/lib/cardflex/configuration.rb +96 -0
- data/lib/cardflex/customer_vault.rb +35 -0
- data/lib/cardflex/customer_vault_gateway.rb +26 -0
- data/lib/cardflex/error_response.rb +18 -0
- data/lib/cardflex/errors.rb +11 -0
- data/lib/cardflex/gateway.rb +35 -0
- data/lib/cardflex/http.rb +68 -0
- data/lib/cardflex/plan.rb +22 -0
- data/lib/cardflex/plan_gateway.rb +23 -0
- data/lib/cardflex/subscription.rb +24 -0
- data/lib/cardflex/subscription_gateway.rb +22 -0
- data/lib/cardflex/success_response.rb +15 -0
- data/lib/cardflex/test/test_values.rb +26 -0
- data/lib/cardflex/three_step.rb +42 -0
- data/lib/cardflex/three_step_gateway.rb +41 -0
- data/lib/cardflex/transaction.rb +52 -0
- data/lib/cardflex/transaction_gateway.rb +23 -0
- data/lib/cardflex/version.rb +9 -0
- data/lib/cardflex/xml.rb +11 -0
- data/lib/cardflex/xml/parser.rb +48 -0
- data/lib/cardflex/xml/serializer.rb +70 -0
- data/lib/ssl/ca-certificates.ca.crt +4190 -0
- data/spec/integration/cardflex/http_spec.rb +72 -0
- data/spec/integration/cardflex/plan_spec.rb +24 -0
- data/spec/integration/cardflex/three_step_gateway_spec.rb +47 -0
- data/spec/integration/cardflex/three_step_spec.rb +37 -0
- data/spec/integration/spec_helper.rb +24 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +45 -0
- data/spec/ssl/certificate.crt +21 -0
- data/spec/ssl/geotrust_global.crt +20 -0
- data/spec/ssl/private_key.pem +30 -0
- data/spec/unit/cardflex/base_module_spec.rb +34 -0
- data/spec/unit/cardflex/configuration_spec.rb +61 -0
- data/spec/unit/cardflex/customer_vault_gateway_spec.rb +10 -0
- data/spec/unit/cardflex/errors_spec.rb +8 -0
- data/spec/unit/cardflex/gateway_spec.rb +11 -0
- data/spec/unit/cardflex/http_spec.rb +18 -0
- data/spec/unit/cardflex/three_step_gateway_spec.rb +29 -0
- data/spec/unit/cardflex/xml_spec.rb +90 -0
- data/spec/unit/spec_helper.rb +1 -0
- metadata +103 -0
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe Cardflex::Http do
|
4
|
+
original_env = Cardflex::Configuration.environment
|
5
|
+
|
6
|
+
describe 'logging' do
|
7
|
+
it 'should log the start of a request' do
|
8
|
+
begin
|
9
|
+
old_logger = Cardflex::Configuration.logger
|
10
|
+
the_time = Time.utc(2014, 1, 1)
|
11
|
+
|
12
|
+
SpecHelper.stub_now(the_time) do
|
13
|
+
new_output = StringIO.new
|
14
|
+
Cardflex::Configuration.logger = Logger.new(new_output)
|
15
|
+
Cardflex::Configuration.logger.level = Logger::DEBUG
|
16
|
+
Cardflex::Configuration.instantiate.http._do_http(Net::HTTP::Get, '/')
|
17
|
+
expect(new_output.string).to include("[Cardflex] [01/Jan/2014 00:00:00 UTC] GET")
|
18
|
+
expect(new_output.string).to include("[Cardflex] [01/Jan/2014 00:00:00 UTC] GET 200")
|
19
|
+
end
|
20
|
+
ensure
|
21
|
+
Cardflex::Configuration.logger = old_logger
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should log an ssl error' do
|
26
|
+
begin
|
27
|
+
old_logger = Cardflex::Configuration.logger
|
28
|
+
the_time = Time.utc(2014, 1, 1)
|
29
|
+
context = OpenSSL::X509::StoreContext.new(OpenSSL::X509::Store.new)
|
30
|
+
|
31
|
+
SpecHelper.stub_now(the_time) do
|
32
|
+
new_output = StringIO.new
|
33
|
+
Cardflex::Configuration.logger = Logger.new(new_output)
|
34
|
+
Cardflex::Configuration.logger.level = Logger::DEBUG
|
35
|
+
Cardflex::Configuration.instantiate.http._verify_ssl_certificate(0, context)
|
36
|
+
expect(new_output.string).to include("SSL Verification failed --")
|
37
|
+
end
|
38
|
+
ensure
|
39
|
+
Cardflex::Configuration.logger = old_logger
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'invalid certificate rejection' do
|
45
|
+
before do
|
46
|
+
@config = Cardflex::Configuration.instantiate
|
47
|
+
@fake_certs_dir = File.expand_path(File.dirname(__FILE__) + '/../../ssl/')
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should reject a self-signed certificate' do
|
51
|
+
expect(@config).to receive(:ca_file).and_return(@fake_certs_dir + 'certificate.crt')
|
52
|
+
|
53
|
+
expect do
|
54
|
+
@config.http._do_http(Net::HTTP::Get, '/')
|
55
|
+
end.to raise_error Cardflex::SSLCertificateError
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'certificate verification' do
|
60
|
+
it 'should verify the ceritificate' do
|
61
|
+
begin
|
62
|
+
Cardflex::Configuration.environment = :test
|
63
|
+
|
64
|
+
expect do
|
65
|
+
Cardflex::Configuration.instantiate.http._do_http(Net::HTTP::Get, '/')
|
66
|
+
end.to_not raise_error
|
67
|
+
ensure
|
68
|
+
Cardflex::Configuration.environment = original_env
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Cardflex::Plan do
|
4
|
+
it 'should create plan' do
|
5
|
+
# have to give a plan id unique to the test account. Since this account is shared by all testers of the api,
|
6
|
+
# it's possible that this will conflict. so we'll accept a conflicting plan-id as a success.
|
7
|
+
plan_id = ('a'..'z').to_a.shuffle.take(10).join
|
8
|
+
req = { :plan => {
|
9
|
+
:payments => 0,
|
10
|
+
:amount => 1.5,
|
11
|
+
:name => 'test_plan',
|
12
|
+
:plan_id => plan_id,
|
13
|
+
:day_frequency => 30
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
res = Cardflex::Plan.create(req)
|
18
|
+
if defined? res.result_code
|
19
|
+
expect(res.result_code.to_i).to eq 300
|
20
|
+
else
|
21
|
+
expect(res.plan.plan[:plan_id]).to eq plan_id
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Cardflex::ThreeStepGateway do
|
4
|
+
it 'should fail step 1 in testing env (missing amount)' do
|
5
|
+
res = Cardflex::Configuration.gateway.three_step.get_form_url({
|
6
|
+
:sale => { :redirect_url => 'http://example.com' }
|
7
|
+
})
|
8
|
+
|
9
|
+
expect(res.success?).to eq false
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should pass step 1 in testing env' do
|
13
|
+
res = Cardflex::Configuration.gateway.three_step.get_form_url({
|
14
|
+
:sale => { :redirect_url => 'http://example.com', :amount => 1.5 }
|
15
|
+
})
|
16
|
+
|
17
|
+
expect(res.success?).to eq true
|
18
|
+
expect(res.three_step.form_url).to match "secure.cardflexonline.com"
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should complete a transaction in testing env' do
|
22
|
+
res = Cardflex::Configuration.gateway.three_step.get_form_url({
|
23
|
+
:sale => { :redirect_url => 'http://example.com', :amount => 1.5 }
|
24
|
+
})
|
25
|
+
|
26
|
+
form_url = res.three_step.form_url
|
27
|
+
token_id = SpecHelper.step_two(form_url)
|
28
|
+
|
29
|
+
complete_result = Cardflex::Configuration.gateway.three_step.complete(token_id)
|
30
|
+
|
31
|
+
expect(complete_result.success?).to be true
|
32
|
+
expect(complete_result.transaction.transaction_id).to_not be nil
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should decline a transaction in testing env' do
|
36
|
+
res = Cardflex::Configuration.gateway.three_step.get_form_url({
|
37
|
+
:sale => { :redirect_url => 'http://example.com', :amount => 0.5 }
|
38
|
+
})
|
39
|
+
|
40
|
+
form_url = res.three_step.form_url
|
41
|
+
token_id = SpecHelper.step_two(form_url)
|
42
|
+
|
43
|
+
res = Cardflex::Configuration.gateway.three_step.complete(token_id)
|
44
|
+
expect(res.success?).to be false
|
45
|
+
expect(res.result_code.to_i).to eq 200
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Cardflex::CustomerVault do
|
4
|
+
it 'should pass step 1 (customer vault)' do
|
5
|
+
res = Cardflex::ThreeStep.add_customer(:redirect_url => "http://example.com")
|
6
|
+
|
7
|
+
expect(res.success?).to be true
|
8
|
+
expect(res.three_step.form_url).to match('secure.cardflexonline.com')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should complete the operation (customer vault)' do
|
12
|
+
form_url = Cardflex::ThreeStep.add_customer(:redirect_url => 'http://example.com').three_step.form_url
|
13
|
+
token_id = SpecHelper.step_two(form_url)
|
14
|
+
res = Cardflex::ThreeStep.complete(token_id)
|
15
|
+
|
16
|
+
expect(res.success?).to be true
|
17
|
+
expect(res.transaction.customer_vault_id).to_not be nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should pass step 1 (subscription)' do
|
21
|
+
# ensure a plan exists. this assumes the Plan code works, check there first if errors arise
|
22
|
+
req = { :plan => {
|
23
|
+
:payments => 0,
|
24
|
+
:amount => 1.5,
|
25
|
+
:name => 'test_plan',
|
26
|
+
:plan_id => 1,
|
27
|
+
:day_frequency => 30
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
Cardflex::Plan.create(req)
|
32
|
+
|
33
|
+
res = Cardflex::ThreeStep.add_subscription({ :redirect_url => 'http://example.com', :plan => { :plan_id => 1 }})
|
34
|
+
expect(res.success?).to be true
|
35
|
+
expect(res.three_step.form_url).to match('secure.cardflexonline.com')
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
unless defined?(INTEGRATION_SPEC_HELPER_LOADED)
|
2
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
Cardflex::Configuration.environment = :test
|
6
|
+
# use the testing api key
|
7
|
+
Cardflex::Configuration.api_key = ENV['CARDFLEX_API_KEY'] || "2F822Rw39fx762MaV7Yy86jXGTC7sCDy"
|
8
|
+
INTEGRATION_SPEC_HELPER_LOADED = true
|
9
|
+
|
10
|
+
module SpecHelper
|
11
|
+
# takes care of step 2, the form posting to the form_url
|
12
|
+
# parses out the token_id and returns it
|
13
|
+
def self.step_two(form_url, attrs={})
|
14
|
+
uri = URI(form_url)
|
15
|
+
attrs.merge!({
|
16
|
+
'billing-cc-number' => Cardflex::Test::Cards::Visa,
|
17
|
+
'billing-cc-exp' => Cardflex::Test::Cards::Expiration
|
18
|
+
})
|
19
|
+
|
20
|
+
res = Net::HTTP.post_form(uri, attrs)
|
21
|
+
CGI::parse(URI(res.header["Location"]).query)['token-id'][0]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
unless defined?(SPEC_HELPER_LOADED)
|
2
|
+
SPEC_HELPER_LOADED = true
|
3
|
+
project_root = File.expand_path(File.dirname(__FILE__) + "/..")
|
4
|
+
|
5
|
+
require "rubygems"
|
6
|
+
|
7
|
+
cardflex_lib = "#{project_root}/lib"
|
8
|
+
$LOAD_PATH << cardflex_lib
|
9
|
+
|
10
|
+
require "cardflex"
|
11
|
+
|
12
|
+
Cardflex::Configuration.api_key = 'fake_api_key'
|
13
|
+
Cardflex::Configuration.environment = :development
|
14
|
+
logger = Logger.new("/dev/null")
|
15
|
+
logger.level = Logger::INFO
|
16
|
+
Cardflex::Configuration.logger = logger
|
17
|
+
|
18
|
+
module SpecHelper
|
19
|
+
def self.stub_now(time)
|
20
|
+
Time.class_eval do
|
21
|
+
class << self
|
22
|
+
alias original_now now
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
(class << Time; self; end).class_eval do
|
27
|
+
define_method(:now) { time }
|
28
|
+
end
|
29
|
+
yield
|
30
|
+
ensure
|
31
|
+
Time.class_eval do
|
32
|
+
class << self
|
33
|
+
alias now original_now
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class FakeResponse
|
39
|
+
attr_reader :body
|
40
|
+
def initialize(body)
|
41
|
+
@body = body
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIDfTCCAmWgAwIBAgIJAN/0qja6lF3KMA0GCSqGSIb3DQEBCwUAMFUxCzAJBgNV
|
3
|
+
BAYTAlVTMREwDwYDVQQIDAhJbGxpbm9pczEQMA4GA1UEBwwHQ2hpY2FnbzEhMB8G
|
4
|
+
A1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMB4XDTE0MTIxNzE1MDkxM1oX
|
5
|
+
DTE3MDkxMTE1MDkxM1owVTELMAkGA1UEBhMCVVMxETAPBgNVBAgMCElsbGlub2lz
|
6
|
+
MRAwDgYDVQQHDAdDaGljYWdvMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0
|
7
|
+
eSBMdGQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDMicqyz6IsAEDz
|
8
|
+
IUi2i8GXQxNh06P5j5VOr/4EtDwSjRfIIJfT0sA6IlPHl2kzToMrpuPTj9wU78JZ
|
9
|
+
Prn1yX9CBEh2liDfStsuu7I4tIpK5hhpXTKztGpSoxaqSmulk9Mhr/sxuEiq/ySm
|
10
|
+
8V/VByql9Wzx9dYjZBUEsRmti2kxDQMPXEoqy4nLOt4Y/S+0cjyD3Np7jzzxcNbS
|
11
|
+
Z5GkFMl9SC+DY8BkKb7NfRzq0+Vhmdj5c8CoO4sJh21H1cfwwJiQ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kn5FoXMv
|
17
|
+
2f57hNG1giJOFsETjQBBsMGAMajlirMmTFchw0NeoT+Qzo9vKuOBYCKqrygj+sXx
|
18
|
+
Kcd5DHMogr8LBxNKFinAbqOv0Ly3h0WQoE/Oh0N0FbrVDWoxgeNfdnxfIO7O4WvI
|
19
|
+
Yymtp54xXk1CphF7+9sbVg9sRs56oBhOwHghS5KBVG9h9NXPBL26LcjAj04wkgBG
|
20
|
+
ZFyoRXfV3sJTh01wH44Kdi4Z3cpwhN3w83pknmIFMY6scmISAVOyv6h3CZ36EX7i
|
21
|
+
T+HJNlzQBKmI7f45InikZtLXApsxuDP+ZnphDRQMGqAKIyPUyeIBDebMQ2LQLKxZ
|
22
|
+
txu85pVvx5e6yiSi3ICGPw+ZtcaqsVdSPGiUDiCFVoeyD+9mAi+e0cBfL+uhJDem
|
23
|
+
NewZVDJ0g4HohEs5dBfNJXHhrFVdzWpfskGEzDLjOlMIT2SWo+DdwsWw5EXvtKco
|
24
|
+
5+AqnQGwSZjEP06C+RIakJI/1tjCzm13z2fa4Y2UZFzFJmImq8wWmawISEJJrv/3
|
25
|
+
cOS25875q6id/QhPOTFKdbVs4YZpDZv4m0uZF+rsgOWPOzwBKG3bAXrR9tfqW+jo
|
26
|
+
AX43ieIGQsn+gbLMU5mEyxPpCfGobqTRoZjGOqBd0PK3QNKOt+UrHW7xcOO8f1GS
|
27
|
+
TgTPb0QwQRsxyxiJNDeo0X93VDtk0997CdXyinrte5F8VUTxlBQX/Nrsya0nKUkF
|
28
|
+
/k/v6VEJYmOq/VhtU1x01MkvFBOfMlzwi31PAknzAl4PO+fJHnOqRP7E161rMn+6
|
29
|
+
Xgg=
|
30
|
+
-----END ENCRYPTED PRIVATE KEY-----
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe Cardflex::BaseModule do
|
4
|
+
class TestClass
|
5
|
+
include Cardflex::BaseModule
|
6
|
+
module Type
|
7
|
+
A = 'a'
|
8
|
+
B = 'b'
|
9
|
+
C = 'c'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should assign instance variables from a hash' do
|
14
|
+
TestClass.set_instance_variables_from_hash({ :test => 'value' })
|
15
|
+
|
16
|
+
expect(TestClass.instance_variables).to include :@test
|
17
|
+
expect(TestClass.instance_variable_get("@test")).to eq 'value'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should preserve nested hashes' do
|
21
|
+
TestClass.set_instance_variables_from_hash({ :test => { :nest => 'nested' }})
|
22
|
+
|
23
|
+
expect(TestClass.instance_variable_get("@test")).to eq({ :nest => 'nested' })
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should snake case a string' do
|
27
|
+
expect(TestClass.snakecase('dash-case-variable')).to eq('dash_case_variable')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should create helper methods' do
|
31
|
+
TestClass.__send__(:create_helper_methods, TestClass::Type)
|
32
|
+
expect(TestClass.methods).to include(:a, :b, :c)
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe Cardflex::Configuration do
|
4
|
+
it 'only sets environment, logger, api_key, and/or endpoint' do
|
5
|
+
sut = Cardflex::Configuration.new({
|
6
|
+
:environment => 'test',
|
7
|
+
:logger => 'test',
|
8
|
+
:api_key => '123',
|
9
|
+
:endpoint => 'test' })
|
10
|
+
expect(sut.api_key).to eq '123'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should require api_key' do
|
14
|
+
expect { Cardflex::Configuration.new }.not_to raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should set environment' do
|
18
|
+
Cardflex::Configuration.environment = :test
|
19
|
+
expect(Cardflex::Configuration.environment).to eq :test
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should throw an ArgumentError if environment is set wrong' do
|
23
|
+
expect { Cardflex::Configuration.environment = :invalid }.to raise_error ArgumentError
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should use http in development, https otherwise' do
|
27
|
+
sut = Cardflex::Configuration.new({ :environment => :test })
|
28
|
+
expect(sut.protocol).to eq "https"
|
29
|
+
expect(sut.ssl?).to be true
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should get the certificate file path' do
|
33
|
+
sut = Cardflex::Configuration.new
|
34
|
+
expect(sut.ca_file).to match "ca-certificates.ca.crt"
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should get the 3 step base url' do
|
38
|
+
sut = Cardflex::Configuration.new({ :environment => :test })
|
39
|
+
expect(sut.three_step_path).to match "/api/v2/three-step"
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should get the api version' do
|
43
|
+
sut = Cardflex::Configuration.new
|
44
|
+
expect(sut.api_version).to eq 3
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should get the correct port' do
|
48
|
+
sut = Cardflex::Configuration.new({ :environment => :test })
|
49
|
+
expect(sut.port).to eq 443
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should get a logger set to INFO level' do
|
53
|
+
sut = Cardflex::Configuration.new
|
54
|
+
expect(sut.logger.level).to be Logger::INFO
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should create a new Http instance out of this config' do
|
58
|
+
sut = Cardflex::Configuration.new
|
59
|
+
expect(sut.http.config).to be sut
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Cardflex::CustomerVaultGateway do
|
4
|
+
it 'should raise an ArgumentError for missing redirect_url and customer_vault_id' do
|
5
|
+
sut = Cardflex::CustomerVaultGateway.new(Cardflex::Configuration.gateway.customer_vault)
|
6
|
+
|
7
|
+
expect { sut.request({ :root => {} }) }.to raise_error(ArgumentError)
|
8
|
+
expect { sut.request({ :root => { :redirect_url => 'test' }}) }.to raise_error(ArgumentError)
|
9
|
+
end
|
10
|
+
end
|