On 8/24/07, Pat Maddox <[EMAIL PROTECTED]> wrote: > On 8/24/07, David Chelimsky <[EMAIL PROTECTED]> wrote: > > describe Widget, "class" do > > it "should provide a list of widgets sorted alphabetically" do > > Widget.should_receive(:find).with(:order => "name ASC") > > Widget.find_alphabetically > > end > > end > > > > You're correct that the refactoring requires you to change the > > object-level examples, and that is something that would be nice to > > avoid. But also keep in mind that in java and C# people refactor > > things like that all the time without batting an eye, because the > > tools make it a one-step activity. Refactoring is changing the design > > of your *system* without changing its behaviour. That doesn't really > > fly all the way down to the object level 100% of the time. > > > > WDYT? > > I think that example is fine up until the model spec. The > find_alphabetically example should hit the db, imo. With the current > spec there's no way to know whether find_alphabetically actually works > or not. You're relying on knowledge of ActiveRecord here, trusting > that the arguments to find are correct.
Au contrare! This all starts with an Integration Test. I didn't post the code but I did mention it. > What I've found when I write specs is that I discover new layers of > services until eventually I get to a layer that actually does > something. When I get there, it's important to have specs that > describe what it does, not how it does it. In the case of > find_alphabetically we care that it returns the items in alphabetical > order. Not that it makes a certain call to the db. I play this both ways and haven't come to a preference, but I'm leaning towards blocking database access from the rspec examples and only allowing it my end to end tests (using Rails Integration Tests or - soon - RSpec's new Story Runner). > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users