On Sat, Dec 22, 2012 at 1:52 AM, Chris Gat <
chri...@gmail.com> wrote:
> I have something similar to the following code
>
> feature Something do
> let!(:var) { FactoryGirl.create(:var) }
> include_examples "these examples"
> end
>
> shared_examples_for "these examples" do
> scenario "test" do
> visit some_url
> expect(page).to have_values(var)
> end
> end
>
> RSpec::Matchers.define :have_values do |expected|
> match do |actual|
> page.has_text(
expected.name)
> end
> end
>
> FactoryGirl.define do
> factory :var do
> sequence(name) {|n| "name#{n}}
> end
> end
>
> The problem I'm having is that let doesn't seem to memoize var into the
> matcher. Since
var.name is a sequence, the name on the page when it is
> visited is different from the check in the customer matcher.
>
> Rspec 2.12, Capybara 2
>
> Thanks in advance for the help
What you've posted should work, assuming that some_url points to a
page that lists all of the var objects' names.
The fact that you're using a sequence shouldn't matter at all. Using
let!() (vs just let()) means that the var object is generated before
the example (scenario in this case), and any call to "var" returns
that same object.
Any chance you could post the exact code (including the controller
action, failure message, and possibly output of the actual html) so we
can see what's really going on? It's quite common for things to get
lost in translation when you write "I have code like this" instead of
the actual code.
Cheers,
David