Skip to content

Instantly share code, notes, and snippets.

View jbrains's full-sized avatar

J. B. Rainsberger jbrains

View GitHub Profile
describe "/registrations/new" do
context "when deciding whether to show the register button" do
it "should hide the button when the user is under 13" do
# Code to set up the form elided
form.age = 12
form.buttons[:submit].should_not be_visible
end
it "should show the button when the user is at least 13" do
# Code to set up the form elided
public class A {
public X doingSomething() {
// code elided
y = doingOtherThing(z);
// code elided
}
public Y doingOtherThing(int z) {
// code elided
}
public interface OtherThing {
Y doingOtherThing(int z);
}
public class A implements OtherThing {
public X doingSomething() {
return doingSomethingWith(this);
}
public X doingSomethingWith(OtherThing otherThing) {
public interface OtherThing {
Y doingOtherThing(int z);
}
public class A {
private OtherThing otherThing;
public A(OtherThing otherThing) {
this.otherThing = otherThing;
}
@Test
// SMELL This test has a structural name. I don't know the
// purpose of configuring these things, so I can't propose
// an intention-revealing name
public void configuresServiceNameTypeAndMechanismCorrectly throws Exception {
properties.setProperty("NegotiateAuthenticator.serviceName", "service");
properties.setProperty("NegotiateAuthenticator.serviceNameType", "1.1");
properties.setProperty("NegotiateAuthenticator.mechanism", "1.2");
// If null causes this class to crash and burn, then either we have
@Test
public void producesServerCredentialsOnDemand() throws Exception {
GSSCredential gssCredential = mock(GSSCredential.class);
// ignore manager.createName() if needed; I don't know how to
// type that in Mockito. In JMock, I'd write
// allowing(manager).createName(with(anything()), with(anything()), ...)
when(manager.createCredential((GSSName) anyObject(), anyInt(), (Oid) anyObject(), anyInt())).thenReturn(gssCredential);
NegotiateAuthenticator authenticator = new NegotiateAuthenticator(manager, properties);
@posting = Posting.create!(
:title => "irrelevant title",
:content => "irrelevant content",
:queued_at => nil,
:published_at => nil
)
describe PostingsController, "when displaying the new entry form" do
it "should include the publication queue in the model" do
Posting.stub!(:publication_queue).and_return([1,2,3])
get 'new'
assigns[:queue].should == [1,2,3]
end
end
describe PostingsController, "when displaying the new entry form" do
it "should include the publication queue in the model" do
anything_but_nil = Object.new
Posting.stub!(:publication_queue).and_return(anything_but_nil)
get 'new'
assigns[:queue].should equal(anything_but_nil)
end
public abstract class FullRepositoryContractTestTemplate extends TestCase {
protected abstract Repository createRepository();
private Repository repository;
protected void setUp() throws Exception {
repository = createRepository();
}