Skip to content

Commit

Permalink
Added duration (in millseconds) to Result. Made code keywords method …
Browse files Browse the repository at this point in the history
…public in java.
  • Loading branch information
aslakhellesoy committed Dec 26, 2010
1 parent 274e466 commit 8f2e3b1
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 22 deletions.
1 change: 1 addition & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

=== Changes
* No more dependencies on external ANSI escape libraries (Ruby:term-ansicolor, Java:Jansi). DIY is better! (Aslak Hellesøy)
* Added duration (in millseconds) to Result. (Aslak Hellesøy)

== 2.3.2 (2010-12-05)

Expand Down
2 changes: 1 addition & 1 deletion java/src/main/java/gherkin/I18n.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public String map(Object keyword) {
}
};

private static String codeKeywordFor(String keyword) {
public static String codeKeywordFor(String keyword) {
return keyword.replaceAll("[\\s',!]", "");
}

Expand Down
11 changes: 10 additions & 1 deletion java/src/main/java/gherkin/JSONParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void step(JSONObject o) {

if(o.containsKey("result")) {
Map r = (Map) o.get("result");
new Result(status(r), errorMessage(r)).replay(reporter);
new Result(status(r), duration(r), errorMessage(r)).replay(reporter);
}

if(o.containsKey("embeddings")) {
Expand Down Expand Up @@ -151,6 +151,10 @@ private String status(Map r) {
return getString(r, "status");
}

private long duration(Map r) {
return getLong(r, "duration");
}

private String errorMessage(Map r) {
return getString(r, "error_message");
}
Expand All @@ -165,6 +169,11 @@ private int getInt(Map map, String key) {
return n == null ? -1 : ((Number) n).intValue();
}

private long getLong(Map map, String key) {
Object n = map.get(key);
return n == null ? -1 : ((Number) n).longValue();
}

private List getList(Map map, String key) {
Object list = map.get(key);
return list == null ? Collections.emptyList() : (List) list;
Expand Down
11 changes: 7 additions & 4 deletions java/src/main/java/gherkin/formatter/PrettyFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public void feature(Feature feature) {
public void background(Background background) {
out.println();
printComments(background.getComments(), " ");
out.println(" " + background.getKeyword() + ": " + background.getName());
printDescription(background.getDescription(), " ", true);
printDescribedStatement(background);
}

public void scenario(Scenario scenario) {
Expand All @@ -97,11 +96,15 @@ private void printTagStatement(TagStatement statement) {
out.println();
printComments(statement.getComments(), " ");
printTags(statement.getTags(), " ");
printDescribedStatement(statement);
}

private void printDescribedStatement(DescribedStatement statement) {
out.print(" ");
out.print(statement.getKeyword());
out.print(": ");
out.print(statement.getName());
printIndentedScenarioLocation(statement.getKeyword(), statement.getName(), statement.getLine());
printIndentedLocation(statement.getKeyword(), statement.getName(), statement.getLine());
out.println();
printDescription(statement.getDescription(), " ", true);
out.flush();
Expand Down Expand Up @@ -306,7 +309,7 @@ private void printTags(List<Tag> tags, String indent) {
out.flush();
}

private void printIndentedScenarioLocation(String keyword, String name, long line) {
private void printIndentedLocation(String keyword, String name, long line) {
if (maxStepLength == -1) return;
int l = keyword.length() + name.length();
maxStepLength = Math.max(maxStepLength, l);
Expand Down
12 changes: 9 additions & 3 deletions java/src/main/java/gherkin/formatter/model/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@

public class Result extends Mappable {
private final String status;
private final long duration;
private final String error_message;
public static final Result SKIPPED = new Result("skipped", null);
public static final Result UNDEFINED = new Result("undefined", null);
public static final Result SKIPPED = new Result("skipped", 0, null);
public static final Result UNDEFINED = new Result("undefined", 0, null);


public Result(String status, String errorMessage) {
public Result(String status, long duration, String errorMessage) {
this.status = status;
this.duration = duration;
this.error_message = errorMessage;
}

public String getStatus() {
return status;
}

public long getDuration() {
return duration;
}

public String getErrorMessage() {
return error_message;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void testShouldPrintNiceColors() throws UnsupportedEncodingException, Int
Thread.sleep(1000);
f.match(new Match(Arrays.asList(new Argument(7, "6")), "somewhere.brainfuck"));
Thread.sleep(1000);
f.result(new Result("failed", "Something\nbad\nhappened"));
f.result(new Result("failed", 55, "Something\nbad\nhappened"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public void failed_passed_is_failed() {
}

private Result passed() {
return new Result("passed", null);
return new Result("passed", 1, null);
}

private Result skipped() {
return new Result("skipped", null);
return new Result("skipped", 0, null);
}

private Result failed() {
return new Result("failed", "error");
return new Result("failed", 2, "error");
}

}
6 changes: 3 additions & 3 deletions lib/gherkin/formatter/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ def replay(formatter)
class Result < Hashable
native_impl('gherkin')

attr_reader :status, :error_message
attr_reader :status, :duration, :error_message

def initialize(status, error_message)
@status, @error_message = status, error_message
def initialize(status, duration, error_message)
@status, @duration, @error_message = status, duration, error_message
end

def replay(formatter)
Expand Down
6 changes: 5 additions & 1 deletion lib/gherkin/json_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def match(o)

def result(o)
if(r = o['result'])
Formatter::Model::Result.new(status(r), error_message(r)).replay(@formatter)
Formatter::Model::Result.new(status(r), duration(r), error_message(r)).replay(@formatter)
end
end

Expand Down Expand Up @@ -126,6 +126,10 @@ def status(r)
r['status']
end

def duration(r)
r['duration']
end

def error_message(r)
r['error_message']
end
Expand Down
8 changes: 4 additions & 4 deletions spec/gherkin/formatter/pretty_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def assert_pretty(input, expected_output=input)

step1 = Model::Step.new([], "Given ", "some stuff", 5)
match1 = Model::Match.new([], "features/step_definitions/bar.rb:56")
result1 = Model::Result.new('passed', nil)
result1 = Model::Result.new('passed', 22, nil)

step2 = Model::Step.new([], "When ", "foo", 6)
match2 = Model::Match.new([], "features/step_definitions/bar.rb:96")
result2 = Model::Result.new('passed', nil)
result2 = Model::Result.new('passed', 33, nil)

@f.steps([step1, step2])
@f.scenario(Model::Scenario.new([], [], "Scenario", "The scenario", "", 4))
Expand Down Expand Up @@ -73,7 +73,7 @@ def assert_pretty(input, expected_output=input)
@f.feature(Model::Feature.new([], [], "Feature", "Hello", "World", 1))
step = Model::Step.new([], "Given ", "some stuff that is longer", 5)
match = Model::Match.new([], "features/step_definitions/bar.rb:56")
result = Model::Result.new('passed', nil)
result = Model::Result.new('passed', 0, nil)

@f.steps([step])
@f.scenario(Model::Scenario.new([], [], "Scenario", "The scenario", "", 4))
Expand All @@ -93,7 +93,7 @@ def assert_pretty(input, expected_output=input)
it "should highlight arguments for regular steps" do
step = Model::Step.new([], "Given ", "I have 999 cukes in my belly", 3)
match = Model::Match.new([Gherkin::Formatter::Argument.new(7, '999')], nil)
result = Model::Result.new('passed', nil)
result = Model::Result.new('passed', 6, nil)

@f.steps([step])
@f.step(step)
Expand Down
3 changes: 2 additions & 1 deletion spec/gherkin/json_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def check_json(json)
},
"result": {
"status": "failed",
"error_message": "You suck"
"error_message": "You suck",
"duration": -1
},
"embeddings": [
{
Expand Down

0 comments on commit 8f2e3b1

Please sign in to comment.