spec/lib/bisu/one_sky_spec.rb in bisu-1.4.3 vs spec/lib/bisu/one_sky_spec.rb in bisu-1.4.4
- old
+ new
@@ -6,16 +6,18 @@
let(:project_id) { 98765 }
let(:file_name) { "file456.json" }
let(:os_response) { File.read("spec/fixtures/sample_one_sky_response.txt") }
- before do
- project = double("OSProject")
- allow_any_instance_of(Onesky::Client).to receive(:project).with(project_id).and_return(project)
- allow(project).to receive(:export_multilingual).with(source_file_name: file_name, file_format: "I18NEXT_MULTILINGUAL_JSON").and_return(os_response)
+ def stub_multilingual(status:, response:)
+ stub_request(:get, "https://platform.api.onesky.io/1/projects/#{project_id}/translations/multilingual").
+ with(query: hash_including(api_key: api_key, file_format: "I18NEXT_MULTILINGUAL_JSON", source_file_name: file_name)).
+ to_return(:status => status, :body => response, :headers => {})
end
+ before { stub_multilingual(status: 200, response: os_response) }
+
it { expect { to_i18 }.not_to raise_error }
it "returns an hash in i18 format" do
expect(to_i18).to eq({
"en" => { "kConnectFacebook" => "Connect with Facebook", "kNoNoNoMr" => "No, no, no. Mr %{name} not here" },
@@ -25,10 +27,10 @@
"ko" => { "kConnectFacebook" => "페이스북으로 접속", "kTwitterServer" => "트위터 서버연결 실패. \\n잠시 후 재시도." }
})
end
context "when OneSky raises an error" do
- before { allow_any_instance_of(Onesky::Client).to receive(:project).and_raise("ups... not allowed!") }
+ before { stub_multilingual(status: 400, response: { error: "ups... not allowed!" }.to_json) }
it "raises that same error" do
expect { to_i18 }.to raise_error /not allowed/
end
end