Permalink
Browse files

Added duration (in millseconds) to Result. Made code keywords method …

…public in java.
  • Loading branch information...
1 parent 274e466 commit 8f2e3b1bf23f0fae226c07d20e505d5a0442af53 @aslakhellesoy aslakhellesoy committed Dec 26, 2010
View
@@ -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)
@@ -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',!]", "");
}
@@ -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")) {
@@ -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");
}
@@ -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;
@@ -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) {
@@ -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();
@@ -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);
@@ -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;
}
@@ -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"));
}
}
@@ -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");
}
}
@@ -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)
@@ -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
@@ -126,6 +126,10 @@ def status(r)
r['status']
end
+ def duration(r)
+ r['duration']
+ end
+
def error_message(r)
r['error_message']
end
@@ -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))
@@ -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))
@@ -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)
@@ -90,7 +90,8 @@ def check_json(json)
},
"result": {
"status": "failed",
- "error_message": "You suck"
+ "error_message": "You suck",
+ "duration": -1
},
"embeddings": [
{

0 comments on commit 8f2e3b1

Please sign in to comment.