3

Closed

shoulda gem doesn't work

description

gem install shoulda
 
require 'rubygems'
require 'shoulda'
 
class MyTest < Test::Unit::TestCase
context "something" do
should "be true" do
  assert true
end
end
end
 
 
Loaded suite a
Started
F
Finished in 1.216803 seconds.
 
1) Failure:
default_test(MyTest)
[C:/M0/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/test/unit/assertions.rb:48:in `assert_bloc
k'
 C:/M0/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/test/unit/assertions.rb:494:in `_wrap_asse
rtion'
 C:/M0/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/test/unit/assertions.rb:46:in `assert_bloc
k'
 C:/M0/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/test/unit/assertions.rb:313:in `flunk'
 C:/M0/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/test/unit/testcase.rb:109:in `default_test
'
 C:/M0/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/test/unit/testcase.rb:78:in `send'
 C:/M0/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/test/unit/testcase.rb:78:in `run'
 C:/M0/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/test/unit/testsuite.rb:34:in `run'
 C:/M0/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/test/unit/testsuite.rb:33:in `each'
 C:/M0/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/test/unit/testsuite.rb:33:in `run'
 C:/M0/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/test/unit/testsuite.rb:34:in `run'
 C:/M0/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/test/unit/testsuite.rb:33:in `each'
 C:/M0/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/test/unit/testsuite.rb:33:in `run'
 C:/M0/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/test/unit/ui/testrunnermediator.rb:46:in `
run_suite'
 C:/M0/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/test/unit/ui/console/testrunner.rb:66:in `
start_mediator'
 C:/M0/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/test/unit/ui/console/testrunner.rb:40:in `
start'
 C:/M0/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/test/unit/ui/testrunnerutilities.rb:28:in
`run'
 C:/M0/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/test/unit/autorunner.rb:216:in `run'
 C:/M0/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/test/unit/autorunner.rb:12:in `run'
 C:/M0/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/test/unit.rb:278]:
Closed Aug 30, 2010 at 6:54 AM by TomasMatousek
Fixed.

comments

wrote Apr 29, 2010 at 1:09 AM

This is probably due to shoua defining methods that are not callable via the Ruby syntax, like test-spec does as well:
 
klass = Class.new do
  define_method("test_spec [MyTest] 001 {should be true}") {}
end
 
If you call klass.instance_methods, that method will be filtered out because other frameworks do things like this:
 
obj.methods.each do |i|
  other_obj.eval "def #{i}\nend"
end
 
Which can fail if obj.methods returns methods that are not valid identifiers in Ruby. However, Ruby itself gets away with the feature, so we need to investigate this further.

wrote Apr 30, 2010 at 11:20 PM

chrisortman wrote May 4, 2010 at 5:15 PM

I must have something else goofy going on too.
In order for me to even run your sanity test from up above I have to do some goofy requiring...it repros the same using iirb.exe

require 'rubygems'
require 'test/unit'

puts Test::Unit::TestCase.methods
require 'shoulda/test_unit'
puts Test::Unit::TestCase.methods
require 'shoulda/test_unit'
puts Test::Unit::TestCase.methods

class MyTest < Test::Unit::TestCase
context "something" do
should "be true" do
  assert true
end
end
end

chrisortman wrote May 4, 2010 at 5:40 PM

What frameworks are you referring to that do:
obj.methods.each do |i|

other_obj.eval "def #{i}\nend"

end

It seems like the right thing to do is to not filter the method out since MRI does not.
MRI would fail if you try to do eval("def test_spec [MyTest] 001\nend")

jimmysch wrote May 4, 2010 at 7:07 PM

Rails uses that pattern all over the place. The reason why we filtered uncallable methods out was for a specific case with .NET interop where Rails would blow up if an ActiveRecord model implemented an interface, simply because of the way we display those methods is not callable ("IFoo.bar"). While I feel this is a bug in Rails, IronRuby still needs to fix it's behavior; even if we mimicked MRI's behavior for displaying methods, IronRuby itself will generate uncallable methods, so that needs to be fixed first.

wrote Jun 7, 2010 at 1:41 AM

wrote Aug 30, 2010 at 6:54 AM

wrote Feb 22, 2013 at 12:39 AM

wrote May 16, 2013 at 12:05 PM