collectiveidea / json_spec

Easily handle JSON in RSpec and Cucumber
rubygems.org/gems/json_spec
MIT License
919 stars 114 forks source link

make "the JSON should have the following" not skip the first assertion #33

Closed levinalex closed 11 years ago

levinalex commented 11 years ago

when using the Then the JSON should have the following-assertion in cucumber like so:

Then the JSON should have the following:
  | string  | "string  |
  | integer | 42       |

the first line of the table was interpreted as a table header and skipped. The attached patch fixes that.

I don't really know how to write a proper test for that.

laserlemon commented 11 years ago

Thank you! :clap:

Could you take a stab at writing a test for this? What comes to mind is duplicating how you came across this bug. Write a table that should fail (and wouldn't have before your fix) and assert that it does indeed fail. Does that make sense? If not, I can try later, just not now. :stuck_out_tongue_winking_eye: Thanks again.

laserlemon commented 11 years ago

Any progress on this? Thanks.

vocaro commented 11 years ago

Could this patch be applied? The issue bit me as well, since the README is completely wrong. The code assumes there is a table header -- because it iterates over table.rows -- while the README examples have no header. Either the README examples need to have a table header, or the code needs to be changed to use table.rows_hash.

laserlemon commented 11 years ago

@vocaro Not without tests. If you could write a test surrounding the fix, that'd be wonderful. Otherwise, I'll get to it when I can. Thank you!

clabrunda commented 11 years ago

+1 for merging this.

I'm not sure there's a good way to write a test for this fix. The only thing I could come up with was to add a tag like @wip (maybe @fail) that makes the scenario pass only if it fails. But that seems to violate the spirit of Given - When - Then.