[rspec-devel] Inverse Thinking, describing behaviors with contexts rather than in contexts
David Chelimsky
dchelimsky at gmail.com
Sun Jun 22 13:56:01 EDT 2008
On Jun 22, 2008, at 12:25 PM, Zach Dennis wrote:
> Two friday's ago I was talking to my pair Cabout a pet peeve I have
> sometimes. Grouping behaviors by contexts, rather then the inverse.
>
> So I ask you, in regards to describing behavior in a particular
> context, have you ever entertained the idea of the describing
> behavior with a particular context?
>
> For example here is an example of describing behavior inside of a
> context:
>
> describe Trip
> context "with no breakfast expenses"
> it "has $0 for breakfast amount"
> end
>
> context "with breakfast expenses" do
> it "has a breakfast amount which is the sum total of breakfast
> expenses"
> end
> end
>
> And here's an example of describing the behavior with contexts:
>
> describe Trip
> behavior "computes breakfast amount" do
> context "with no breakfast expenses" do
> it "is $0"
> end
>
> context "with breakfast expenses" do
> it "is the sum of all breakfast expenses"
> end
> end
> end
>
> The difference is subtle, but it inverts how behaviors are
> described. It also groups contexts for a particular behavior
> together, rather than grouping the behaviors to a particular context.
>
> It does add another level of verbosity, but it makes my contexts
> more meaningful because the setup is directly tied to the behavior
> I'm testing, rather than potentially many behaviors which rely on
> the same setup.
>
> I'm just thinking out loud at this point, but I'm interested in
> hearing your thoughts.
Bravo! That's my initial thought.
This all makes sense to me, though there are pros and cons. If you're
a fan of common setup, this won't work too well. If you're a fan of
organization/layout for communication, this seems to make sense.
I'm not ready to add behaviour as an alias for context/describe/
example_group just yet, but I'd say you should do so in your projects
- and feel free to write about this in your chapters - just be sure to
point out both approaches and the pros/cons of each.
Good?
More information about the rspec-devel
mailing list