Shoulda issue: no more "should have_instance_methods" ?

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?

daze wrote in post #969974:

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.)

Best,

daze wrote in post #969974:

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.)

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?

daze wrote in post #970132:

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.

Best,

daze wrote in post #970132:

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.

…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.

Great, thanks!

So in summary:

1) Use rspec and shoulda together, as the Thoughtbot team (which
created shoulda) is saying they are using rspec
2) 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!

2) 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.

-philip

Great, thanks!

So in summary:

  1. Use rspec and shoulda together, as the Thoughtbot team (which

created shoulda) is saying they are using rspec

PS - I cant find the original but this looks like a republish of the Thoughtbot writup on the status of Shoulda: http://www.l-exp.com/m/feed/show/971486