summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples.rb
diff options
context:
space:
mode:
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