I am writing some specs related to permissions for different kinds of
users. Every user has some common examples to test in many different
specs. For example, all users can view, and edit their profile.
Also, all users can view their own “history.” So I have two spec
files, say profile_controller_spec and history_controller_spec.
Using these files RSpec will give an error that ‘User’ is already
registered as a shared group, even though they are defined in separate
files and example groups.
Is it suppose to behave that way? Seems like a hassle to have to
prepend the controller name to each shared_example_for.
files and example groups.
Shared examples are not scoped to groups they are defined in. They are
global.
Is it suppose to behave that way?
Yes
Seems like a hassle to have to prepend the controller name to each shared_example_for.
It’s not really behaving like a User so this:
it_should_behave_like “User”
doesn’t tell me anything I need to know. It’s actually behaving like a
profile controller handling any user, so I’d probably write this:
it_should_behave_like “the profile controller handling any user”
In terms of being able to scope shared examples, I think that’s a good
idea and something we should consider for rspec-2. If you’re interested,
feel free to create an issue at Issues · rspec/rspec-core · GitHub and, even better, fork the
repo and submit a patch.
Cheers,
David
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.