summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorMichael Herold <michael.j.herold@gmail.com>2015-10-23 14:39:16 -0500
committerdblock <dblock@dblock.org>2015-10-25 15:05:18 -0400
commitf5fb158559e39be3b0ba09abfa7b881c0e39c762 (patch)
tree5ddd5d234096cb288d882bfa096d2fb9092dda4f /spec
parent20a03f0542144b9949b55a7348340d95c6dca5d7 (diff)
downloadhashie-f5fb158559e39be3b0ba09abfa7b881c0e39c762.tar.gz
Ensure that MethodQuery methods return booleans.
The documentation about the MethodQuery module spells out the expected behavior. While the spec suite appeared to be testing the same, the RSpec matchers were not actually checking the behavior properly. This lead to a divergence between the expected behavior, as outlined in the module documentation, and the actual behavior, as tested in the spec suite. This is the reason that #299 is happening: the expected behavior is not the actual behavior. I have included a test for #299 to show that it works as expected in this branch. This change makes the spec suite match the behavior in the module documentation, then modifies the methods to match the documentated specification. Lastly, I took the time to clean up the MethodQuery module for two reasons: 1. The old implementation used Regexps on the stringified method names, which is unnecessary since we have the wonderful `String#end_with?` method to check the suffix of a strings. 2. The old logic was difficult to reason through, so I clarified the intent of the methods by reducing the complexity of the conditionals and extracting meaningful methods where possible.
Diffstat (limited to 'spec')
-rw-r--r--spec/hashie/dash_spec.rb23
-rw-r--r--spec/hashie/extensions/method_access_spec.rb10
2 files changed, 30 insertions, 3 deletions
diff --git a/spec/hashie/dash_spec.rb b/spec/hashie/dash_spec.rb
index 1de533f..453d62f 100644
--- a/spec/hashie/dash_spec.rb
+++ b/spec/hashie/dash_spec.rb
@@ -511,3 +511,26 @@ context 'Dynamic Dash Class' do
expect(my_property).to eq(my_orig)
end
end
+
+context 'with method access' do
+ class DashWithMethodAccess < Hashie::Dash
+ include Hashie::Extensions::IndifferentAccess
+ include Hashie::Extensions::MethodQuery
+
+ property :test
+ end
+
+ subject(:dash) { DashWithMethodAccess.new(test: 'value') }
+
+ describe '#test' do
+ subject { dash.test }
+
+ it { is_expected.to eq('value') }
+ end
+
+ describe '#test?' do
+ subject { dash.test? }
+
+ it { is_expected.to eq true }
+ end
+end
diff --git a/spec/hashie/extensions/method_access_spec.rb b/spec/hashie/extensions/method_access_spec.rb
index b48b4e1..03528e4 100644
--- a/spec/hashie/extensions/method_access_spec.rb
+++ b/spec/hashie/extensions/method_access_spec.rb
@@ -92,15 +92,19 @@ describe Hashie::Extensions::MethodQuery do
subject { QueryHash }
it 'is true for non-nil string key values' do
- expect(subject.new('abc' => 123)).to be_abc
+ expect(subject.new('abc' => 123).abc?).to eq true
end
it 'is true for non-nil symbol key values' do
- expect(subject.new(abc: 123)).to be_abc
+ expect(subject.new(abc: 123).abc?).to eq true
+ end
+
+ it 'is false for false key values' do
+ expect(subject.new(abc: false).abc?).to eq false
end
it 'is false for nil key values' do
- expect(subject.new(abc: false)).not_to be_abc
+ expect(subject.new(abc: nil).abc?).to eq false
end
it 'raises a NoMethodError for non-set keys' do