[rspec-users] DRYing up stories

Kamal Fariz kamal.fariz at gmail.com
Thu Jan 24 04:47:37 EST 2008


> With 1.1.1 you can do this:
>
> Given "$n_users in the system" do |num_users|
>  case num_users
>  when "a user"
>    # one user case
>  when /(\d*) users/
>    # multi user case using $1
>  end
> end
>
> With 1.1.2 you can do this:
>
> Given /(a|\d*) users? in the system/ do |num_users|
>  num_users = (num_users == 'a') ? 1 : num_users.to_i
>  (1..num_users).each do
>   # ...
>  end
> end

Didn't know you could do that! Thanks. So, the step will yield all the  
matches in the same order regexp will populate the matches array?


Regards,
kamal


More information about the rspec-users mailing list