spec/acfs/resource/attributes_spec.rb in acfs-1.7.0 vs spec/acfs/resource/attributes_spec.rb in acfs-2.0.0
- old
+ new
@@ -39,11 +39,11 @@
expect(model.new.attributes).to eq(name: 'John', age: 25)
end
end
describe '#write_attributes' do
- subject(:action) { -> { m.write_attributes(params, **opts) } }
+ subject(:action) { m.write_attributes(params, **opts) }
before do
model.attribute :name, :string, default: 'John'
model.attribute :age, :integer, default: 25
model.send :define_method, :name= do |name|
@@ -54,40 +54,40 @@
let(:params) { {name: 'James'} }
let(:opts) { {} }
let(:m) { model.new }
it 'updates attributes' do
- expect(action).to change(m, :attributes)
+ expect { action }.to change(m, :attributes)
.from(name: 'The Great John', age: 25)
.to(name: 'The Great James', age: 25)
end
context 'without non-hash params' do
let(:params) { 'James' }
- it { expect(action).not_to change(m, :attributes) }
- it { expect(action.call).to eq false }
+ it { expect { action }.not_to change(m, :attributes) }
+ it { expect(action).to be false }
end
context 'with unknown attributes' do
let(:params) { {name: 'James', born_at: 'today'} }
- it { expect(action).not_to raise_error }
+ it { expect { action }.not_to raise_error }
it 'updates known attributes and store unknown' do
- expect(action).to change(m, :attributes)
+ expect { action }.to change(m, :attributes)
.from(name: 'The Great John', age: 25)
.to(name: 'The Great James', age: 25, born_at: 'today')
end
context 'with unknown: :raise option' do
let(:opts) { {unknown: :raise} }
- it { expect(action).to raise_error(ArgumentError, /unknown attribute/i) }
+ it { expect { action }.to raise_error(ArgumentError, /unknown attribute/i) }
it do
expect do
- action.call
+ action
rescue StandardError
true
end.not_to change(m, :attributes)
end
end