-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fail fast on missing methods in state object #2099
Merged
chrisroos
merged 17 commits into
master
from
fail-fast-on-missing-methods-in-state-object
Nov 17, 2015
Merged
Fail fast on missing methods in state object #2099
chrisroos
merged 17 commits into
master
from
fail-fast-on-missing-methods-in-state-object
Nov 17, 2015
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Caught by the integration/regression tests.
Caught by the integration/regression tests.
Caught by the integration/regression tests.
Caught by the integration/regression tests.
Caught by the integration/regression tests.
Caught by the integration/regression tests.
Caught by the integration/regression tests.
Caught by the integration/regression tests.
Caught by the integration/regression tests.
Caught by the integration/regression tests.
Caught by the integration/regression tests.
Caught by the integration/regression tests.
Caught by the integration/regression tests.
Ensure the color variable is set on the state before trying to call it.
Ensure the accommodation_charge variable is set on the state before trying to call it.
I'm planning to override `State#method_missing` so that it raises a `NoMethodError` if you attempt to read an attribute value without first setting it. We always want to be able to read `error` and `response` irrespective of whether they've been set. I initially tried using `attr_reader` but that means that `error` and `state` are left out of the hash returned from `State#to_hash`. Setting them in this call to `super` ensures that `#to_hash` works as expected.
So that it raises a NoMethodError unless the method being called is a writer (i.e. ends in =). This should help avoid errors in our code by failing fast if we try to access a method that's not previously been set on the `State`.
chrisroos
added a commit
that referenced
this pull request
Nov 17, 2015
…n-state-object Fail fast on missing methods in state object
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This supersedes PR #2071
The
SmartAnswer::State
object is anOpenStruct
which means that it responds to undefined methods withnil
. This can lead to hard to find bugs innext_node
blocks (particularly larger ones, e.g. this one in pay-leave-for-parents) as a simple typo will mean that the program runs but doesn't return the desired result.The main change in this PR overrides
SmartAnswer::State#method_missing
so that it raises aNoMethodError
exception if we try to call a method that's not previously been defined.I've also updated all Smart Answer flows where the code was relying on the old behaviour of the
State
object, by explicitly setting the variables to nil that are used later in the flow.I started out with the commit titled "Implement State#method_missing" as the first commit in order to identify the flows that needed updating. I moved it to become the final commit once I was happy that I'd updated all flows.