我對rspec測試相當新,我試圖測試用戶的位置時遇到問題。這是一個測試模擬country_code的行爲以阻止來自特定區域的垃圾郵件。將變量傳遞給rspec測試
這是我服務的代碼:
class GeocodeUserAuthorizer
def initialize(user_country_code:)
@user_country_code = user_country_code
end
def authorize!
user_continent = ISO3166::Country.new(user_country_code).continent
if user_continent == 'Africa'
return true
else
return false
end
end
end
這裏是我的規格文件的代碼:
require 'spec_helper'
describe GeocodeUserAuthorizer do
context 'with a user connecting from an authorized country' do
it { expect(GeocodeUserAuthorizer.new.authorize!(user_country_code: { "CA" })).to eql(true) }
end
end
,這裏是故障代碼:
Failures:
1) GeocodeUserAuthorizer with a user connecting from an authorized country Failure/Error: it { expect(GeocodeUserAuthorizer.new.authorize!(user_country_code: { "CA" })).to eql(true) } ArgumentError: missing keyword: user_country_code # ./app/services/geocode_user_authorizer.rb:2:in
initialize' # ./spec/services/geocode_user_authorizer_spec.rb:16:in
new' # ./spec/services/geocode_user_authorizer_spec.rb:16:inblock (3 levels) in <top (required)>' # ./spec/spec_helper.rb:56:in
block (3 levels) in ' # ./spec/spec_helper.rb:56:in `block (2 levels) in '
燦有人幫忙嗎?