spec/user_spec.rb in tijuana_client-0.2.4 vs spec/user_spec.rb in tijuana_client-0.3.0
- old
+ new
@@ -1,7 +1,9 @@
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+# frozen_string_literal: true
+require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+
describe TijuanaClient::User do
subject { TijuanaClient.new(host: 'test.com') }
describe 'configuration' do
it 'should propagate the host' do
@@ -9,28 +11,28 @@
end
end
describe '.post_json_request' do
let(:client) { TijuanaClient::Client.new }
- subject { TijuanaClient::User.new({client: client }) }
+ subject { TijuanaClient::User.new({ client: client }) }
let(:path) { '/foo' }
- let(:params) { {first_name: 'Nathan'} }
+ let(:params) { { first_name: 'Nathan' } }
it 'should jsonify params' do
- expect(client).to receive(:post_request).with('/foo', {'data' => JSON.generate({ first_name: 'Nathan'}) } )
- client.post_json_request(path, params)
+ expect(client).to receive(:post_request).with('/foo', { 'data' => JSON.generate({ first_name: 'Nathan' }) })
+ client.post_json_request(path, params)
end
end
describe 'create' do
let(:body) { '' }
- let(:request_body){ {'data' => JSON.generate({ first_name: 'Nathan'})} }
+ let(:request_body) { { 'data' => JSON.generate({ first_name: 'Nathan' }) } }
let(:request_path) { '/api/users/' }
before(:each) do
- stub_post(request_path).with(body: request_body).to_return(:body => body, :status => status,
- :headers => { content_type: "application/json; charset=utf-8"})
+ stub_post(request_path).with(body: request_body).to_return(body: body, status: status,
+ headers: { content_type: 'application/json; charset=utf-8' })
end
describe 'success' do
let(:status) { 200 }
@@ -64,33 +66,33 @@
expect { subject.user.create(first_name: 'Nathan') }.to raise_exception(TijuanaClient::EmailValidationError)
end
end
end
- describe "basic authentication" do
- subject { TijuanaClient.new(host: 'test.com', username: 'username', password: 'password')}
+ describe 'basic authentication' do
+ subject { TijuanaClient.new(host: 'test.com', username: 'username', password: 'password') }
- let(:body) { "" }
- let(:request_body) { {'data' => JSON.generate({ first_name: 'Nathan'})} }
+ let(:body) { '' }
+ let(:request_body) { { 'data' => JSON.generate({ first_name: 'Nathan' }) } }
let(:request_path) { '/api/users/' }
before(:each) do
- stub_request(:post, "https://test.com#{request_path}").with(basic_auth: ['username', 'password'], body: request_body)
- .to_return(:body => body, :status => status, :headers => { content_type: "application/json; charset=utf-8"})
+ stub_request(:post, "https://test.com#{request_path}").with(basic_auth: %w[username password], body: request_body)
+ .to_return(body: body, status: status, headers: { content_type: 'application/json; charset=utf-8' })
end
- describe "success" do
+ describe 'success' do
let(:status) { 200 }
- it "should create a user" do
+ it 'should create a user' do
subject.user.create(first_name: 'Nathan')
end
end
- describe "unauthorized" do
+ describe 'unauthorized' do
let(:status) { 401 }
- it "should return nil" do
+ it 'should return nil' do
expect { subject.user.create(first_name: 'Nathan') }.to raise_exception(StandardError)
end
end
end
end