I’m using Shoulda.
After copying the code here…
… http://joshuaclayton.github.com/code/2009/07/14/should-act-as-list.html…
into my test_helper file so I can test acts_as_list, I came across
issues. For one I realized I had to get rid of the _ between the
“should” and “have” in past cases, but here, I get this error when I
run my unit test:
./test/test_helper.rb:28:in should_act_as_list': undefined method have_instance_methods’ for ArticleTest:Class (NoMethodError)
What’s the Rails 3 way to test acts_as_list with Shoulda?
I’m using Shoulda.
After copying the code here…
… http://joshuaclayton.github.com/code/2009/07/14/should-act-as-list.html…
into my test_helper file so I can test acts_as_list, I came across
issues. For one I realized I had to get rid of the _ between the
“should” and “have” in past cases, but here, I get this error when I
run my unit test:
./test/test_helper.rb:28:in should_act_as_list': undefined method have_instance_methods’ for ArticleTest:Class (NoMethodError)
What’s the Rails 3 way to test acts_as_list with Shoulda?
Well, that whole way of testing is wrongheaded and always was. You
shouldn’t be testing for implementation details like instance methods;
rather, you should be testing for behavior. (Although I sometimes test
for acts_as_list by making sure the appropriate module was included into
the class.)
Usually, if you’re trying to poke into internals, something is wrong
with your tests. The object being tested should generally be considered
a black box. (BTW, consider RSpec instead of Shoulda. I believe even
Shoulda’s own developers have switched.)
On Wed, Dec 22, 2010 at 11:45 AM, Marnen Laibow-Koser [email protected]wrote:
run my unit test:
the class.)
Usually, if you’re trying to poke into internals, something is wrong
with your tests. The object being tested should generally be considered
a black box. (BTW, consider RSpec instead of Shoulda. I believe even
Shoulda’s own developers have switched.)
From what I understand, Thoughtbot, the developers of Shoulda are using
Rspec however are continuing to use and support the Shoulda helpers…
as
they make life easier than not using them.
Well, that whole way of testing is wrongheaded and always was. You
shouldn’t be testing for implementation details like instance methods;
rather, you should be testing for behavior. (Although I sometimes test
for acts_as_list by making sure the appropriate module was included into
the class.)
Usually, if you’re trying to poke into internals, something is wrong
with your tests. The object being tested should generally be considered
a black box. (BTW, consider RSpec instead of Shoulda. I believe even
Shoulda’s own developers have switched.)
Okay - so what exactly should I do regarding testing the acts_as_list
gem?
As I said above, test behavior, or test that the one module (I think
it’s Acts::somethingorother) got included in the appropriate class.
From what I understand, Thoughtbot, the developers of Shoulda are using
Rspec however are continuing to use and support the Shoulda helpers… as
they make life easier than not using them.
I will get rspec I guess. You can use rspec and shoulda together,
right?
I’m not sure, but I don’t understand why you’d want to. Shoulda is
basically an RSpec knockoff.
On Wed, Dec 22, 2010 at 3:33 PM, Marnen Laibow-Koser [email protected]wrote:
a black box. (BTW, consider RSpec instead of Shoulda. I believe even
From what I understand, Thoughtbot, the developers of Shoulda are using
Rspec however are continuing to use and support the Shoulda helpers…
as
they make life easier than not using them.
I will get rspec I guess. You can use rspec and shoulda together,
right?
I’m not sure, but I don’t understand why you’d want to. Shoulda is
basically an RSpec knockoff.
…yes you can use Rspec with shoulda, in fact that is the intended use
at
this point as the Thoughtbot team say they are using Rspec. I think the
matchers add value to rspec and to date no one has shown me how to do
some
of the same things that the shoulda matchers do in pure rspec w/o
shoulda.
Well, that whole way of testing is wrongheaded and always was. You
shouldn’t be testing for implementation details like instance methods;
rather, you should be testing for behavior. (Although I sometimes test
for acts_as_list by making sure the appropriate module was included into
the class.)
Usually, if you’re trying to poke into internals, something is wrong
with your tests. The object being tested should generally be considered
a black box. (BTW, consider RSpec instead of Shoulda. I believe even
Shoulda’s own developers have switched.)
Okay - so what exactly should I do regarding testing the acts_as_list
gem?
From what I understand, Thoughtbot, the developers of Shoulda are using
Rspec however are continuing to use and support the Shoulda helpers… as
they make life easier than not using them.
I will get rspec I guess. You can use rspec and shoulda together,
right?
To test acts_as_list, test the behavior of it (or test the
inclusion of that one module in the appropriate class)
I don’t know what “that one module is” or how to test its inclusion in
a class though… but otherwise thanks guys!
If it were me I wouldn’t test for the inclusion of the class. I’d test
to the behavior only. Test that when you move an item around in the
list the results are what you expect. That way when you decide to
switch to “acts_as_list_on_steroids_fu” which implements the same
behavior but adds all kinds of other goodies your tests will still pass
and more importantly they pass for the right reason.