> I would argue that it's unimportant -- even at the unit-level -- *how*
> the test is passing. If every time you run the test it passes, then
> the code does what you specify it does. When there's a problem,
> identify the bug and write a new unit, integration, or functional test
> that eliminates the unexpected behavior, then make that test pass.
I think effectively what you
are saying is that it doesn't matter if it actually tests what it is
supposed to as long as it passes. If you later discover that the app
is not doing what it is supposed to then add more tests.
A good point. I would summarize it more like this:
"If you verify, to the best of your ability, that the software behaves
the way you want it to, then you're finished testing until you
discover an exception. When you have a repeatable case where the
software does not behave the way you expect, at that point you will
have steps to cause the unexpected behavior (and therefore a test)."
It's not *only* the case that the test needs to pass; as you
mentioned, it is also the case that the test needs to verify behavior.
Sounds like we definitely agree on that. And you're right; it's that
"to the best of your ability" that's tricky. Seems like that's where
we went down different paths.
> ...it's up to ActiveRecord to
> hold up its end of the bargain.
I am not trying to test that ActiveRecord sorts correctly, I am trying
to test that I have correctly coded the scope. I don't know how I
would assert that the named scope is passing the correct sorting
params. Can you enlighten me?
I would probably do something like this in RSpec:
require 'spec_helper'
describe ClassWithNamedScope do
describe 'scope :foo' do
it 'exists' do
ClassWithNamedScope.scopes.should be_include(:foo)
end
it 'specifies that foo is true' do
ClassWithNamedScope.stub(:named_scope)
ClassWithNamedScope.should_receive(:named_scope).with(:active, :conditions
=> {:foo => true})
load "#{RAILS_ROOT}/app/models/class_with_named_scope.rb"
end
end
end
Similar stubbing and reloading should also work in test_unit with
Mocha or somesuch, right?