These are chat archives for mojotech/pioneer

13th
Oct 2014
Jarid Margolin
@jaridmargolin
Oct 13 2014 05:55
Would putting asserts in widgets be bad form for any reason? If so, would love the explanation.
Dominik Guzei
@DominikGuzei
Oct 13 2014 08:51
@jaridmargolin I think its just a good separation of concerns, widgets are more like reusable "views" that provide a API to simplify your step definitions.
Sam Saccone
@samccone
Oct 13 2014 13:11
hey @DominikGuzei @jaridmargolin
those are good issues @DominikGuzei , would you mind fileing a few issues and we can look into them?
Jarid Margolin
@jaridmargolin
Oct 13 2014 18:35

@DominikGuzei - Just to explain a little further... I have a list item that will be manipulated in various scenarios. In each scenario, the contents of the list item will need to be verified. The code to do so is a little verbose:

return Q.all([
  item.author().should.eventually.match(new RegExp(user.name)),
  item.preview().should.eventually.match(new RegExp(msg.prev))
])

Each scenario will also check different values (5 total). The example above happens to check the author, and preview values...

So I created a method isMatch to dynamically verify contents of the list item.

    isMatch: function (matches) {
      var asserts = [];

      _.each(matches, function (val, key) {
        var regExp = new RegExp(val);
        asserts.push(this[key]().should.eventually.match(regExp));
      }, this);

      return Q.all(asserts);
    },
This method could be reused for various widgets. Perhaps rather than a method on the widget, I could pull it out into its own module and simply require it in my steps:
  isMatch: function (wdgt, matches) {
      var asserts = [];

      _.each(matches, function (val, key) {
        var regExp = new RegExp(val);
        asserts.push(wdgt[key]().should.eventually.match(regExp));
      });

      return Q.all(asserts);
    },
Dominik Guzei
@DominikGuzei
Oct 13 2014 18:38
@jaridmargolin Yeah, looks like a pretty special case – pulling it out into a helper function is probably the cleanest way
In my opinion widgets should really only "wrap" your DOM, but of course that's just one opinion, if it feels better for you to have it on the widget then do it
Jarid Margolin
@jaridmargolin
Oct 13 2014 18:42
No I had the same feeling. Actually the reason I asked in the first place. It just felt wrong.
Even abstracting it into its own module seems a little off to me. Seems like assertions should be coupled with the steps.
Sam Saccone
@samccone
Oct 13 2014 18:43
yeah
i have tried each
i have found that widgets returning promisies for methods
and either rejecting or fufilling is th best kind of contract
Dominik Guzei
@DominikGuzei
Oct 13 2014 18:44
Yes its similar to abstracting assertions in unit tests – it mostly makes things more complicated to understand later on
Sometimes it works great though … it also depends on the API