Add should_change macro
Reported by Ryan McGeary | July 8th, 2008 @ 10:14 PM
Update We took a slightly different approach than what was originally discussed here. Please read the comments.
This is dependent on Ticket #51.
This branch adds a new should_differ macro. This macro is akin to the assert_difference assertion used in Active Support.
(rmm5t/shoulda should_differ)
http://github.com/rmm5t/shoulda/...
Here's some example usage:
context "Creating a post"
setup do
Post.create
end
should_differ "Post.count", :by => 1
end
This idea was discussed on the shoulda mailing list: http://groups.google.com/group/s...
The relevant commit: http://github.com/rmm5t/shoulda/...
Comments and changes to this ticket
-
David Lowenfels July 9th, 2008 @ 02:58 AM
I'd like to see :from and :to options, as mentioned in the mailing list thread linked above.
Also, I think "should_change" is a little more semantic.
I suppose I could make a branch for "should_change" that leaves out the :by option. But why not roll all three into one?
-
Ryan McGeary July 9th, 2008 @ 09:57 AM
- → Title changed from Add should_differ macro to Add should_differ or should_change macro
I liked David's suggestions. Here is a new branch that incorporates them:
(rmm5t/shoulda should_change)
http://github.com/rmm5t/shoulda/...
Relevant commit: http://github.com/rmm5t/shoulda/...
I also added a should_not_change macro in this branch since the conventions behind should_change made it a logical addition.
-
David Lowenfels July 9th, 2008 @ 12:27 PM
great work! it would also be sweet if :from and :to would accept regular expressions, and in that case assert_match instead of assert_equal.
In this case it would be better to use inspect instead of manually quoting, e.g.:
stmt << " from #{from.inspect}" if from stmt << " to #{to.inspect}" if to stmt << " by #{by}" if byI would like implement this but not sure how to properly branch a branch...
my git-fu is not up to par yet. And when I cloned your branch, the new changes weren't in there?
BTW, does the use of @_before_should_change mean that only one should_change is possible per context??
-
Ryan McGeary July 9th, 2008 @ 03:20 PM
David,
I agree regarding inspect, regexes, and assert_match.
No, the use of @_before_should_change does not mean you are limited. You can still use multiple should_change calls per context. That instance variable is just reset for every macro call. The setup is run for every test, so effectively, it just gets reused and reset for every should_change. As an example, the tests actually run multiple should_change's per context:
-
Ryan McGeary July 9th, 2008 @ 10:08 PM
David,
Check the recent enhancements to my should_change branch:
http://github.com/rmm5t/shoulda/...
I chose to use the case equality operator instead of assert_match so that anything that supports === will work against the :from and :to options. This allows for the possibilities of:
should_change "@value", :from => /\w/, :to => /\d/ # or even should_change "@value", :from => String, :to => FixnumThanks for the suggestions and ideas; I think they made for a nice outcome.
-
Tammer Saleh July 9th, 2008 @ 10:25 PM
This is unrelated, but we should probably modify should_match to use
the === operator.
-
-
Ryan McGeary July 11th, 2008 @ 09:27 PM
- → Title changed from Add should_differ or should_change macro to Add should_change macro
(committed to thoughtbot/shoulda master)
-
Ryan McGeary July 30th, 2008 @ 09:17 AM
- → State changed from new to committed
- → Assigned user changed from Tammer Saleh to Ryan McGeary
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
