spec/integration/yard/arstotzka/wrapper_spec.rb in arstotzka-1.0.3 vs spec/integration/yard/arstotzka/wrapper_spec.rb in arstotzka-1.0.4
- old
+ new
@@ -1,28 +1,44 @@
-# frozen_string_literal: true
+# frozen_string_literal: truie
-require 'spec_helper'
-
describe Arstotzka::Wrapper do
+ subject(:wrapper) { described_class.new(clazz: clazz, type: type) }
+
+ let(:type) { nil }
+ let(:clazz) { nil }
+
describe 'yard' do
describe '#wrap' do
- subject { described_class.new(clazz: clazz, type: type) }
- let(:clazz) { nil }
- let(:type) { nil }
-
- context 'when definning clazz' do
+ context 'when clazz is defined' do
let(:clazz) { Person }
+ let(:value) { 'john' }
- it 'returns the valued wrapped in a class' do
- expect(subject.wrap('John')).to eq(Person.new('John'))
+ it 'wraps value with the clazz' do
+ expect(wrapper.wrap(value)).to eq(Person.new(value))
end
end
- context 'when defing type' do
- let(:type) { :integer }
+ context 'when type is defined' do
+ let(:type) { :integer }
+ let(:value) { %w[10 20 30] }
- it 'casts all values' do
- expect(subject.wrap(%w[10 20 30])).to eq([10, 20, 30])
+ it 'converts value to type' do
+ expect(wrapper.wrap(value)).to eq([10, 20, 30])
+ end
+ end
+
+ context 'when type and class is defined' do
+ let(:type) { :string }
+ let(:clazz) { Request }
+ let(:value) { { 'key' => 'value' } }
+ let(:request) { wrapper.wrap(value) }
+
+ it 'returns a wrapped object' do
+ expect(request).to be_a(Request)
+ end
+
+ it 'casts before wrapping' do
+ expect(request.payload).to eq('{"key"=>"value"}')
end
end
end
end
end