Skip to content

Commit

Permalink
Merge pull request #11 from ellemenno/1.1.1
Browse files Browse the repository at this point in the history
1.1.1
  • Loading branch information
ellemenno committed Dec 9, 2014
2 parents 67498af + 227980e commit d64eb14
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 48 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ a simple specification framework for Loom
Download the library into its matching sdk folder:

```bash
$ curl -L -o ~/.loom/sdks/sprint32/libs/Spec.loomlib \
https://github.com/pixeldroid/spec-ls/releases/download/v1.1.0/Spec-sprint32.loomlib
$ curl -L -o ~/.loom/sdks/sprint33/libs/Spec.loomlib \
https://github.com/pixeldroid/spec-ls/releases/download/v1.1.1/Spec-sprint33.loomlib
```

To uninstall, simply delete the file:

```bash
$ rm ~/.loom/sdks/sprint32/libs/Spec.loomlib
$ rm ~/.loom/sdks/sprint33/libs/Spec.loomlib
```


Expand Down
58 changes: 54 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ Rake::Task[:clobber].enhance ["lib:uninstall"]
task :default => :list_targets

task :list_targets do |t, args|
lib_sdk = lib_config['sdk_version']
test_sdk = test_config['sdk_version']
puts "Spec Rakefile running on Ruby #{RUBY_VERSION}"
puts " lib SDK: #{lib_sdk}"
puts " test SDK: #{test_sdk}"
system("rake -T")
puts ''
end
Expand Down Expand Up @@ -67,6 +71,21 @@ file APP => LIBRARY do |t, args|
end


desc "sets the provided SDK version into lib/loom.config and test/loom.config"
task :set, [:sdk] => "lib:uninstall" do |t, args|
args.with_defaults(:sdk => 'sprint33')
sdk_version = args.sdk

lib_config['sdk_version'] = sdk_version
test_config['sdk_version'] = sdk_version

write_lib_config(lib_config)
write_test_config(test_config)

puts "[#{t.name}] task completed, sdk updated to #{sdk_version}"
puts ''
end

namespace :lib do

desc "builds Spec.loomlib for the SDK specified in lib/loom.config"
Expand Down Expand Up @@ -144,7 +163,18 @@ namespace :test do
puts "[#{t.name}] running #{t.prerequisites[0]}..."

sdk_version = test_config['sdk_version']
cmd = %Q[#{sdk_root}/#{sdk_version}/tools/loomexec test/bin/SpecTest.loom]
cmd = %Q[#{sdk_root}/#{sdk_version}/tools/loomexec test/bin/SpecTest.loom --format ansi]
try(cmd, "failed to run .loom")

puts ''
end

desc "runs SpecTest.loom for CI"
task :ci => APP do |t, args|
puts "[#{t.name}] running #{t.prerequisites[0]}..."

sdk_version = test_config['sdk_version']
cmd = %Q[#{sdk_root}/#{sdk_version}/tools/loomexec test/bin/SpecTest.loom --format junit --format console]
try(cmd, "failed to run .loom")

puts ''
Expand All @@ -153,16 +183,36 @@ namespace :test do
end


def lib_config_file
File.join('lib', 'loom.config')
end

def test_config_file
File.join('test', 'loom.config')
end

def lib_config
@lib_loom_config || (@lib_loom_config = JSON.parse(File.read(File.join('lib', 'loom.config'))))
@lib_loom_config || (@lib_loom_config = JSON.parse(File.read(lib_config_file)))
end

def test_config
@test_loom_config || (@test_loom_config = JSON.parse(File.read(File.join('test', 'loom.config'))))
@test_loom_config || (@test_loom_config = JSON.parse(File.read(test_config_file)))
end

def write_lib_config(config)
File.open(lib_config_file, 'w') { |f| f.write(JSON.pretty_generate(config)) }
end

def write_test_config(config)
File.open(test_config_file, 'w') { |f| f.write(JSON.pretty_generate(config)) }
end

def home
ENV['LOOM_HOME'] || Dir.home
end

def sdk_root
File.join(Dir.home, '.loom', 'sdks')
File.join(home, '.loom', 'sdks')
end

def try(cmd, failure_message)
Expand Down
2 changes: 1 addition & 1 deletion lib/loom.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"sdk_version": "sprint31"
"sdk_version": "sprint33"
}
75 changes: 47 additions & 28 deletions lib/src/pixeldroid/bdd/Matcher.ls
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,29 @@ package pixeldroid.bdd
var match:Boolean = (isTypeMatch(value, type) || isSubtypeMatch(value, type));

result.success = rectifiedMatch( match );
result.description = "'" +value.getFullTypeName() +"' " +rectifiedPhrase("toBeA") +" '" +type.getFullName() +"'";
result.description = "'" +value.getFullTypeName() +"' " +rectifiedPrefix("toBeA") +" '" +type.getFullName() +"'";

if (!result.success) result.message = "types " +rectifiedSuffix("do", true) +" match.";

context.addResult(result);
}

public function toBeNaN():void
{
result.success = rectifiedMatch( (isNaN(value as Number)) );
result.description = "'" +value.toString() +"' " +rectifiedPhrase("toBeNaN");
result.description = "'" +value.toString() +"' " +rectifiedPrefix("toBeNaN");

if (!result.success) result.message = "value " +rectifiedSuffix("is", true) +" not-a-number.";

context.addResult(result);
}

public function toBeNull():void
{
result.success = rectifiedMatch( (value == null) );
result.description = "'" +value.toString() +"' " +rectifiedPhrase("toBeNull");
result.description = "'" +value.toString() +"' " +rectifiedPrefix("toBeNull");

if (!result.success) result.message = "value " +rectifiedSuffix("is", true) +" null.";

context.addResult(result);
}
Expand All @@ -67,7 +73,9 @@ package pixeldroid.bdd
{
var match:Boolean = isNaN(value as Number) ? false : !!(value);
result.success = rectifiedMatch( match );
result.description = "'" +value.toString() +"' " +rectifiedPhrase("toBeTruthy");
result.description = "'" +value.toString() +"' " +rectifiedPrefix("toBeTruthy");

if (!result.success) result.message = "value " +rectifiedSuffix("is", true) +" truthy.";

context.addResult(result);
}
Expand All @@ -76,23 +84,29 @@ package pixeldroid.bdd
{
var match:Boolean = isNaN(value as Number) ? true : !!!(value);
result.success = rectifiedMatch( match );
result.description = "'" +value.toString() +"' " +rectifiedPhrase("toBeFalsey");
result.description = "'" +value.toString() +"' " +rectifiedPrefix("toBeFalsey");

if (!result.success) result.message = "value " +rectifiedSuffix("is", true) +" falsey.";

context.addResult(result);
}

public function toBeLessThan(value2:Number):void
{
result.success = rectifiedMatch( (value < value2) );
result.description = value.toString() +" " +rectifiedPhrase("toBeLessThan") +" " +value2.toString();
result.description = value.toString() +" " +rectifiedPrefix("toBeLessThan") +" " +value2.toString();

if (!result.success) result.message = "value " +rectifiedSuffix("is", true) +" less than " +value2.toString() +".";

context.addResult(result);
}

public function toBeGreaterThan(value2:Number):void
{
result.success = rectifiedMatch( (value > value2) );
result.description = value.toString() +" " +rectifiedPhrase("toBeGreaterThan") +" " +value2.toString();
result.description = value.toString() +" " +rectifiedPrefix("toBeGreaterThan") +" " +value2.toString();

if (!result.success) result.message = "value " +rectifiedSuffix("is", true) +" greater than " +value2.toString() +".";

context.addResult(result);
}
Expand All @@ -103,13 +117,17 @@ package pixeldroid.bdd
{
var s:String = value as String;
result.success = rectifiedMatch( (s.length == 0) );
result.description = "'" +value.toString() +"' " +rectifiedPhrase("toBeEmpty");
result.description = "'" +value.toString() +"' " +rectifiedPrefix("toBeEmpty");

if (!result.success) result.message = "String " +rectifiedSuffix("is", true) +" empty.";
}
else if (isTypeMatch(value, Vector))
{
var vector:Vector = value as Vector;
result.success = rectifiedMatch( (vector.length == 0) );
result.description = "[" +value.toString() +"] " +rectifiedPhrase("toBeEmpty");
result.description = "[" +value.toString() +"] " +rectifiedPrefix("toBeEmpty");

if (!result.success) result.message = "Vector " +rectifiedSuffix("is", true) +" empty.";
}
else
{
Expand All @@ -125,14 +143,18 @@ package pixeldroid.bdd
{
var string1:String = value as String;
var string2:String = value2 as String;
result.success = rectifiedMatch( (string1.indexOf(string2, 0) > -1) );
result.description = "'" +string1 +"' " +rectifiedPhrase("toContain") +" '" +string2 +"'";
result.success = rectifiedMatch( (string1.indexOf(string2) > -1) );
result.description = "'" +string1 +"' " +rectifiedPrefix("toContain") +" '" +string2 +"'";

if (!result.success) result.message = "String " +rectifiedSuffix("does", true) +" contain '" +string2 +"'.";
}
else if (isTypeMatch(value, Vector))
{
var vector:Vector = value as Vector;
result.success = rectifiedMatch( (vector.contains(value2)) );
result.description = "[" +value.toString() +"] " +rectifiedPhrase("toContain") +" '" +value2.toString() +"'";
result.description = "[" +value.toString() +"] " +rectifiedPrefix("toContain") +" '" +value2.toString() +"'";

if (!result.success) result.message = "Vector " +rectifiedSuffix("does", true) +" contain '" +value2.toString() +"'.";
}
else
{
Expand All @@ -145,15 +167,17 @@ package pixeldroid.bdd
public function toEqual(value2:Object):void
{
result.success = rectifiedMatch( (value == value2) );
result.description = "'" +value.toString() +"' " +rectifiedPhrase("toEqual") +" '" +value2.toString() +"'";
result.description = "'" +value.toString() +"' " +rectifiedPrefix("toEqual") +" '" +value2.toString() +"'";

if (!result.success) result.message = "values " +rectifiedSuffix("are", true) +" equal.";

context.addResult(result);
}

public function from(value2:Number):void
{
result.success = rectifiedMatch( (Math.abs(value2 - value) <= absoluteDelta) );
result.description = value.toString() +" " +rectifiedPhrase("toBePlusOrMinus") +" " +absoluteDelta.toString() +" from " +value2.toString();
result.description = value.toString() +" " +rectifiedPrefix("toBePlusOrMinus") +" " +absoluteDelta.toString() +" from " +value2.toString();
result.message = value.toString() +" is " +Math.abs(value2 - value) +" away from " +value2.toString();

context.addResult(result);
Expand All @@ -168,23 +192,18 @@ package pixeldroid.bdd

private function isSubtypeMatch(value:Object, type:Type):Boolean
{
/*
FIXME: there is a known bug with is, as, and instanceof operators on Type variables,
which is preventing inheritance & interface matching from working:
LOOM-1759 - http://theengine.co/forums/troubleshooting-and-issues/topics/bug-type-ops-only-work-on-literal-values/posts/4445
// i.e., these fail when invoked against the input variable to this function named type,
// but would operate correctly if invoked against a literal type like Number, or MyClass:
var match:Boolean = (value instanceof type);
var match:Boolean = (value is type);
var match:Boolean = ((value as type) != null);
*/
return ((value instanceof type) || (value is type) || ((value as type) != null));
}

private function rectifiedPhrase(phrase:String):String
private function rectifiedSuffix(phrase:String, flipped:Boolean = false):String
{
if (flipped) return (!positive ? phrase : phrase +' not');
return (positive ? phrase : phrase +' not');
}

private function rectifiedPrefix(phrase:String, flipped:Boolean = false):String
{
if (flipped) return (!positive ? phrase : 'not ' +phrase);
return (positive ? phrase : 'not ' +phrase);
}

Expand All @@ -201,4 +220,4 @@ package pixeldroid.bdd
}

}
}
}
11 changes: 8 additions & 3 deletions lib/src/pixeldroid/bdd/Spec.ls
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package pixeldroid.bdd

public class Spec
{
public static const version:String = '1.1.0';
public static const version:String = '1.1.1';

private static var things:Vector.<Thing> = [];
private static var reporters:ReporterManager = new ReporterManager();
Expand All @@ -25,7 +25,12 @@ package pixeldroid.bdd

public static function addReporter(reporter:Reporter):void
{
reporters.add(reporter);
if (reporter) reporters.add(reporter);
}

public static function get numReporters():Number
{
return reporters.length;
}

public static function execute(seed:Number=-1):void
Expand All @@ -44,4 +49,4 @@ package pixeldroid.bdd
}

}
}
}
1 change: 1 addition & 0 deletions lib/src/pixeldroid/bdd/reporters/ConsoleReporter.ls
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ package pixeldroid.bdd.reporters
}

trace(verdict +' expect ' +result.description);
if (!result.success) trace(' (' +result.message +')');
}

}
Expand Down
4 changes: 1 addition & 3 deletions lib/src/pixeldroid/bdd/reporters/JunitReporter.ls
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package pixeldroid.bdd.reporters
public function init(specInfo:SpecInfo):void
{
xml = new XMLDocument();
xml.linkEndChild(xml.newDeclaration('version="1.0" encoding="UTF-8"'));
xml.linkEndChild(xml.newDeclaration('xml version="1.0" encoding="UTF-8"'));
xml.linkEndChild(xml.newComment(specInfo.toString()));

suites = xml.newElement('testsuites');
Expand All @@ -41,7 +41,6 @@ package pixeldroid.bdd.reporters
var i:Number;
var n:Number = e.numResults;
var result:MatchResult;
var time:Number;

var suite:XMLElement = xml.newElement('testsuite');
suite.setAttribute('name', e.description);
Expand All @@ -52,7 +51,6 @@ package pixeldroid.bdd.reporters

for (i = 0; i < n; i++)
{
time = Platform.getEpochTime();
result = e.getResult(i);

test = xml.newElement('testcase');
Expand Down
7 changes: 6 additions & 1 deletion lib/src/pixeldroid/bdd/reporters/ReporterManager.ls
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ package pixeldroid.bdd.reporters
private var reporters:Vector.<Reporter> = [];


public function get length():Number
{
return reporters.length;
}


public function add(reporter:Reporter):void
{
reporters.push(reporter);
}


public function init(specInfo:SpecInfo):void
{
for each (var reporter:Reporter in reporters)
Expand Down
Binary file modified terminal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/loom.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"sdk_version": "sprint31"
"sdk_version": "sprint33"
}
Loading

0 comments on commit d64eb14

Please sign in to comment.