Skip to content

Commit

Permalink
improved the server mojo
Browse files Browse the repository at this point in the history
  • Loading branch information
searls committed Jul 4, 2011
1 parent 632abe5 commit ea61d9f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
23 changes: 17 additions & 6 deletions src/main/java/com/github/searls/jasmine/ServerMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
*/
public class ServerMojo extends AbstractJasmineMojo {

public static final String INSTRUCTION_FORMAT =
"\n\n" +
"Server started--it's time to spec some JavaScript! You can run your specs as you develop by visiting this URL in a web browser: \n\n" +
" http://localhost:%s"+
"\n\n" +
"The server will monitor these two directories for scripts that you add, remove, and change:\n\n" +
" source directory: %s\n\n"+
" spec directory: %s"+
"\n\n"+
"Just leave this process running as you test-drive your code, refreshing your browser window to re-run your specs. You can kill the server with Ctrl-C when you're done.";

private Server server = new Server();

private RelativizesFilePaths relativizesFilePaths = new RelativizesFilePaths();
Expand Down Expand Up @@ -59,12 +70,12 @@ private void startServer() throws Exception {
server.join();
}

private String buildServerInstructions() {
return "\n\n" +
"Server started--it's time to spec some JavaScript! You can run your specs as you develop by visiting this URL in a web browser: \n\n\t" +
"http://localhost:"+serverPort+
"\n\n" +
"Just leave this process running as you test-drive your code, refreshing your browser window to re-run your specs. You can kill the server with Ctrl-C when you're done.";
private String buildServerInstructions() throws IOException {
return String.format(
INSTRUCTION_FORMAT,
serverPort,
relativizesFilePaths.relativize(mavenProject.getBasedir(), sources.getDirectory()),
relativizesFilePaths.relativize(mavenProject.getBasedir(), specs.getDirectory()));
}

private String manualSpecRunnerPath() throws IOException {
Expand Down
19 changes: 13 additions & 6 deletions src/test/java/com/github/searls/jasmine/ServerMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import com.github.searls.jasmine.io.RelativizesFilePaths;
import com.github.searls.jasmine.model.ScriptSearch;
import com.github.searls.jasmine.server.JasmineResourceHandler;

@RunWith(MockitoJUnitRunner.class)
public class ServerMojoTest {

private static final String SPECS_DIR = "spec dir";
private static final String SOURCE_DIR = "source dir";
private static final int PORT = 8923;
private static final String RELATIVE_TARGET_DIR = "some dir";
private static final String MANUAL_SPEC_RUNNER_NAME = "nacho specs";
Expand All @@ -42,31 +46,34 @@ public class ServerMojoTest {
@Mock private RelativizesFilePaths relativizesFilePaths;
@Mock private File baseDir;
@Mock private File targetDir;
@Mock(answer=Answers.RETURNS_DEEP_STUBS) private ScriptSearch sources;
@Mock(answer=Answers.RETURNS_DEEP_STUBS) private ScriptSearch specs;



@Captor private ArgumentCaptor<SelectChannelConnector> connectorCaptor;
@Captor private ArgumentCaptor<HandlerList> handlerListCaptor;

@Before
public void arrangeAndAct() throws Exception {
subject.sources = sources;
subject.specs = specs;
subject.setLog(log);
subject.serverPort = PORT;
subject.jasmineTargetDir = targetDir;
subject.manualSpecRunnerHtmlFileName = MANUAL_SPEC_RUNNER_NAME;
when(baseDir.getAbsolutePath()).thenReturn(BASE_DIR);
when(mavenProject.getBasedir()).thenReturn(baseDir);
when(relativizesFilePaths.relativize(baseDir,targetDir)).thenReturn(RELATIVE_TARGET_DIR);
when(relativizesFilePaths.relativize(baseDir,sources.getDirectory())).thenReturn(SOURCE_DIR);
when(relativizesFilePaths.relativize(baseDir,specs.getDirectory())).thenReturn(SPECS_DIR);

subject.run();
}

@Test
public void logsInstructions() {
verify(log).info(
"\n\n" +
"Server started--it's time to spec some JavaScript! You can run your specs as you develop by visiting this URL in a web browser: \n\n\t" +
"http://localhost:"+PORT+
"\n\n" +
"Just leave this process running as you test-drive your code, refreshing your browser window to re-run your specs. You can kill the server with Ctrl-C when you're done.");
verify(log).info(String.format(ServerMojo.INSTRUCTION_FORMAT, PORT, SOURCE_DIR, SPECS_DIR));
}

@Test
Expand Down

0 comments on commit ea61d9f

Please sign in to comment.