Skip to content
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

Add more descriptive message to missing key exception #38

Merged
merged 4 commits into from
Nov 16, 2016

Conversation

mcelicalderon
Copy link
Contributor

This should take care of #24, adds a descriptive error about a missing key in the hash passed to the render method on a SimpleTemplates::Template object.

@mcelicalderon
Copy link
Contributor Author

@jsl Already had this when I read your comment. But anyone else can take it from here.

@@ -10,7 +10,7 @@
it "fails when the placeholder name is not in the given Hash" do
->(){
target.new('not_in_substitutions', 0, true).render(substitutions)
}.must_raise KeyError
}.must_raise RuntimeError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mcelicalderon this looks good. sorry I didn't review this for so long. But, how about re-raising the KeyError with the more specific error, instead of the more generic RuntimeError? I think KeyError is really a good exception type for this error. Then we can just delete the change to the test and it should pass, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, totally makes sense, I'll change that.

@jsl
Copy link
Member

jsl commented Nov 11, 2016

@acamino can you please add a test to ensure that the error text is ok (you may want to tweak so it reads bette), and what we expect? Also, change to KeyError instead of RuntimeError.

@jsl jsl assigned jsl and acamino and unassigned jsl Nov 11, 2016
@jsl
Copy link
Member

jsl commented Nov 11, 2016

Actually, what do you think about making it a custom error like InterpolationError?

@acamino
Copy link
Contributor

acamino commented Nov 11, 2016

I'll go for adding a custom error. InterpolationError has a revealing name. Additionally to me handling the KeyError is a side effect of the implementation.

acamino and others added 3 commits November 11, 2016 17:10
- Use `#` to make it explicit the test describes an instance method.
- Put the example that corresponds to the happy path in the beginning.
- Remove unnecessary parens from lambda expression. When there are no arguments
  it is safe to ommit the parens.
@acamino
Copy link
Contributor

acamino commented Nov 11, 2016

@jsl CI was complaining because this branch didn't have a .travis.yml. I've just pulled it from master and now we're green.

@jsl
Copy link
Member

jsl commented Nov 16, 2016

LGTM!

@acamino acamino merged commit e73c432 into master Nov 16, 2016
@acamino acamino deleted the add_descriptive_error_for_missing_key branch November 16, 2016 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants