JMongol / twilio-test-toolkit

Twilio Test Toolkit (TTT) makes it easy to write RSpec integration tests for Rails applications that serve Twilio phone callbacks.
MIT License
29 stars 22 forks source link

Dynamic methods in call scope #10

Closed pgib closed 10 years ago

pgib commented 10 years ago

Take advantage of Ruby's dynamic nature to make future additions for TwiML nouns and verbs tests a little easier. Calling #has_foo? or #has_foo?("bar") for any foo will now just work. When passed "bar", the default behaviour is to do a substring match on the element's .inner_text property. If an exact match is needed as the case was/is with #has_play?, a class call to #has_element will be necessary. e.g.:

has_element "Foo", :exact_inner_match => true

This will create #has_foo?(inner) using an exact match.

There is also a has_bar_on_foo?(bat) pattern where bar can either be the equivalent of TwiML-style lowercase camelCase attributes, or a Ruby snake_case. The following two calls are same:

has_finishOnKey_on_record?("#")
has_finish_on_key_on_record("#")

... which will check for:

<Record finishOnKey="#"></Record>

Care was taken to preserve the previous behaviour of the has_nnnn? methods.

JMongol commented 10 years ago

Cool idea - give me a few days to have a look and then I'll merge this and the other change list.

JMongol commented 10 years ago

Actually got to it now - looks great. Thanks!