floatdrop / stream-assert

Assertion library for streams
18 stars 4 forks source link

assert.any #4

Open raftheunis87 opened 8 years ago

raftheunis87 commented 8 years ago

Hey,

First of all, thanks for this library! It really makes testing streams a joy :-).

I got a problem with the any assertion. Maybe I'm using the wrong syntax. What I try to do is the following:

this.source = vinylFs.src(['test/specs/streams/**'], {nodir: true});
it('should test if the files are in the stream', function (done) {
    this.source
      .pipe(assert.any(function (file) {
        expect(file.path).toContain('include_me.css');
      }))
      .on('assertion', function (err) {
        done.fail(err);
      })
      .pipe(pi.devnull(function () {
        done();
      }));
  });

The problem is that it is checking all the files in the stream against the 'include_me.css'. I get the following output:

A copy stream should test if the files are in the stream
  - Expected '/test/specs/streams/copy/resources/src/shared/style/include_me_2.css' to contain 'include_me.css'.
  - Expected 'test/specs/streams/copy/resources/src/authenticated/style/img/included.jpg' to contain 'include_me.css'.
  - Expected 'test/specs/streams/copy/resources/src/shared/style/img/included.jpg' to contain 'include_me.css'.

The 'include_me.css' is also in this filepath as well, but it is not logged as an error because it matches.

What can I do to resolve this issue?

Kind regards,

Raf

floatdrop commented 8 years ago

@raftheunis87 seems like expect(file.path).toContain('include_me.css'); is printing out Exprecetd... on every call. You can look into expect library for a way to disable this logging.

raftheunis87 commented 8 years ago

@floatdrop Thanks for the quick reply.

It's not just the logging, the test is actually failing :-(

floatdrop commented 8 years ago

@raftheunis87 can you print error message in assertion event?

raftheunis87 commented 8 years ago

@floatdrop

.on('assertion', function (err) {
        console.log(err);
        done.fail(err);
      })

The console.log is not printed, so I guess the event doesn't happen. But it's weird that I get the following output:

A copy stream should test if the files are in the stream
  - Expected '/test/specs/streams/copy/resources/src/shared/style/include_me_2.css' to contain 'include_me.css'.
  - Expected 'test/specs/streams/copy/resources/src/authenticated/style/img/included.jpg' to contain 'include_me.css'.
  - Expected 'test/specs/streams/copy/resources/src/shared/style/img/included.jpg' to contain 'include_me.css'.

To me it seems like he is matching against all the files in the stream, even if there was a match with one of them? I would expect that when 1 of the files matches, that it doesn't matter anymore if any of the other files match, right?

floatdrop commented 8 years ago

I would expect that when 1 of the files matches, that it doesn't matter anymore if any of the other files match, right?

@raftheunis87 didn't think about it, but it does make sense.

raftheunis87 commented 8 years ago

@floatdrop Is this going to be fixed? Or should I look into it and create a pull request? :)

floatdrop commented 8 years ago

@raftheunis87 PR would be awesome :)