drewbourne/hamcrest-as3

ArrayMatchers doesn't work for Vectors (only 1.0.2, not in current source)

karfau opened this issue · 5 comments

How could this best be solved, so the assertions with vectors can be as nice as the ones I do with those untyped Arrays?

I would really like a souloution where I can use the same matcher for Vector.<*> and Array, if possible.

Or is this not implemented to remain compatible with FP9?

I had a go at trying to implement this - and the problem is that there is no common base class for Vector and Array - I believe this is probably because it's too late for Adobe to edit the inheritance chain for Vector.

After a fair bit of tinkering, I've so far not come up with a way to implement this - I'm still resorting to properties-within-the-test-object style matchers. It's certainly not trivial.

I just wanted to write some code to give some more details about my problem by writing some code I couldn't use with the lib delivered with the latest FlashBuilder (tried this at work last week). So I made up a Test for this purpose:

  var vector:Vector. = new Vector.();
  vector.push("some", "Strings", "to", "test");
  assertThat(vector, both(arrayWithSize(4)).and(
    everyItem(allOf( isA(String),
                    hasPropertyWithValue("length", greaterThanOrEqualTo(2))
    ))));

in a project of mine wich uses a downloaded hamcrest-1.0.2.swc: and it failed with the following message:

de.karfau.abstract::Hamcrest.short_description : Error: Expected: (an Array with size <4> and every item is (is an instance of String and has property "length" with a value greater than or equal to <2>))
     but: was 
    at global/assertThatMatcher()[/Users/simeon/Documents/Flex Builder 3/hamcrest/src/org/hamcrest/assertThatMatcher.as:29]
    at global/org.hamcrest::assertThat()[/Users/simeon/Documents/Flex Builder 3/hamcrest/src/org/hamcrest/assertThat.as:44]
    at de.karfau.abstract::Hamcrest/short_description()[D:\Coden\_projects\_git\as3-abstract\test\de\karfau\abstract\Hamcrest.as:25]
    at Function/http://adobe.com/AS3/2006/builtin::call()
    at asunit.framework::Method/execute()[D:\Coden\_doc\asunit-4.0\src\asunit\framework\Method.as:64]
     [...]

So viewing this stacktrace I wanted to recheck the sources which I just imported as libproject for better navigation. But I couldn't find something where "Array" was in use.
So I had a strange idea: using the lib-project as lib for the test.
And viola: the test PASSES!

So it seems the issue is solved for the current source, but exists in 1.0.2 (and earlier?).

When are u planning to create a new release, so I can replace the lib at work ;) ?

karfau

Theres a zip with the latest SWC and API Docs under the hamcrest-as3 downloads

Great.
If u verified that the issue is fixed in this lib, than this issue can be closed.

It will take one or two weeks until I have time to verify it, if it didn't already happen.

karfau

closing as fixed since at least version 1.1.0.