Created
June 30, 2010 04:35
-
-
Save dfl/458242 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# example unit test context using should_change and should_not_change | |
context "Given a user" do | |
setup do | |
@user = create_user | |
end | |
context "when sent initials with a hyphen and lower case" do | |
setup do | |
@user.update_attributes!( :first_name => "Jason", :last_name => "happy-Klein" ) | |
end | |
should_change("initials", :to => "JHK"){ @user.reload.initials } | |
end | |
context "when sent #enable_api!" do | |
setup do | |
@user.enable_api! | |
end | |
should_change("user api key", :from => nil){ @user.api_key } | |
context "and then sent #disable_api!" do | |
setup do | |
@user.disable_api! | |
end | |
should_change("user api key", :to => ""){ @user.api_key } | |
end | |
end | |
context "given a project" do | |
setup do | |
User.current_user = @user | |
create_project | |
end | |
context "when destroyed in hosted version" do | |
setup do | |
@user.destroy | |
end | |
should_change("projects", :by => -1){ Project.count } | |
end | |
context "when destroyed in installable version" do | |
setup do | |
License.stubs(:installed?).returns(true) | |
@user.destroy | |
end | |
should_not_change("project count"){ Project.count } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment