Rails: Getestete Bereiche mit RSpec testen

Ich bin das neue zu testen-Rails-web-Applikationen und RSpec. Ich arbeite mit legacy-code und brauchen, um hinzuzufügen, tests. Also, was ist der beste Weg, um zu testen, Entfernungsmesser und scopes mit RSpec?

Finde ich in Google ein paar Ansätze, aber Sie sind nicht ideal.
Zum Beispiel:

http://paulsturgess.co.uk/articles/show/93-using-rspec-to-test-a-named_scope-in-ruby-on-rails

it "excludes users that are not active" do
    @user = Factory(:user, :active => false)
    User.active.should_not include(@user)
end

oder

http://h1labs.com/notebook/2008/8/21/testing-named-scope-with-rspec

it "should have a published named scope that returns ..." do
  Post.published.proxy_options.should == {:conditions => {:published => true}}
end

Find ich am besten Vorgehen (IMHO) im "Rail-Test-Rezepte":

should_match_find_method :active_only { :active == true }

wo should_match_find_method benutzerdefinierte helper-Methode

InformationsquelleAutor der Frage andrykonchin | 2011-06-26

Schreibe einen Kommentar