collectiveidea/json_spec — pull request #56 by taiki45 (2013-11-09 15:58:24+00:00)
Title: Add probability testing matcher

Thanks to this great gem!:gem:

When I use this to my game app API server's cucumber testing, I wanted to test the API response which have probability. And worse than that, the app can't fix probability in testing.

So I wanted to write cucumber feature like this:

```cucumber
Then the JSON at "1/id" should be one of 1, 2
```

I wrote a step to test that in my app test like this:

```ruby
Then /^(?:JSON|json)(?: response)?(?: at "(.*)")? should( not)? be one of (.*)$/ do |path, negative, exp|
if negative
eval(exp).to_json.should_not include_json(JsonSpec.remember(find_value_by_path(last_json, path)))
else
eval(exp).to_json.should include_json(JsonSpec.remember(find_value_by_path(last_json, path)))
end
end

def find_value_by_path(json, path)
JsonSpec::Helpers.normalize_json(json, path)
end
```

In feature file:

```cucumber
And JSON response at "list/1/id" should be one of [1, 2]
```

And I thought this is useful!

So **I suggest `be_one_of` matcher to this great gem!!**

`be_one_of` RSpec matcher is almost ornament because everyone can use `include?` or something to test probability behavior. But in Cucumber, we want a handy step. So I suggested this matcher.

How do you think?