Skip to content

Instantly share code, notes, and snippets.

@coreyhaines
Forked from stevenharman/some_spec.rb
Created March 20, 2012 23:44
Show Gist options
  • Save coreyhaines/2142600 to your computer and use it in GitHub Desktop.
Save coreyhaines/2142600 to your computer and use it in GitHub Desktop.
Using Rspec's "let" inside an "it" block. Crazy? Yes. Useful? Occasionally.
describe "#mentions_story?" do
subject { described_class.new(file) }
let(:file) { "COMMIT_EDITMSG" }
before do
File.stub(:read).with(file) { example_commit_message(@relevant_part) }
end
context "commit message contains the special Pivotal Tracker story syntax" do
it "matches just the number" do
@relevant_part = "[#8675309]"
subject.should be_mentions_story("8675309")
end
it "matches state change and number" do
@relevant_part = "[Fixes #8675309]"
subject.should be_mentions_story("8675309")
end
end
context "commit message doesn't contain the special Pivotal Tracker story syntax" do
it "doesn't match without brackets" do
@relevant_part = "#8675309"
subject.should_not be_mentions_story("8675309")
end
end
end
@stevenharman
Copy link

Yeah, that's what I ended up doing, but didn't like it. And to be honest, I'm not sure why... aesthetics I suppose.

@nickqw12
Copy link

nickqw12 commented Jul 4, 2018

What would be the best way to achieve something similar?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment