summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples.rb
diff options
context:
space:
mode:
authorMichael Herold <opensource@michaeljherold.com>2020-10-29 19:49:08 -0500
committerGitHub <noreply@github.com>2020-10-29 19:49:08 -0500
commit75410a6657090348de7bff3e5eab8aa684e49c38 (patch)
tree27e0eab23a209706b738bcfcf5736220fc3ac871 /spec/support/shared_examples.rb
parent59d04c851e8ae80d82e93d82059e591eaa7718a7 (diff)
parentf152e25912d0b93ff08b8964eb757200ad4b6f32 (diff)
downloadhashie-75410a6657090348de7bff3e5eab8aa684e49c38.tar.gz
Merge pull request #537 from michaelherold/dash-consistency
Fix inconsistencies with Dash defaults
Diffstat (limited to 'spec/support/shared_examples.rb')
-rw-r--r--spec/support/shared_examples.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/support/shared_examples.rb b/spec/support/shared_examples.rb
new file mode 100644
index 0000000..df05592
--- /dev/null
+++ b/spec/support/shared_examples.rb
@@ -0,0 +1,26 @@
+RSpec.shared_examples 'Dash default handling' do |property, name = property|
+ it 'uses the default when initializing' do
+ expect(test.new(name => nil).public_send(property)).to eq ''
+ end
+
+ it 'allows you to set the value to nil with the hash writer' do
+ trash = test.new(name => 'foo')
+ trash[name] = nil
+
+ expect(trash.public_send(property)).to be_nil
+ end
+
+ it 'allows you to set the value to nil with the method writer' do
+ trash = test.new(name => 'foo')
+ trash[name] = nil
+
+ expect(trash.public_send(property)).to be_nil
+ end
+
+ it 'uses the default when updating with defaults' do
+ trash = test.new(name => 'foo')
+ trash.update_attributes!(name => nil)
+
+ expect(trash.public_send(property)).to eq ''
+ end
+end