Skip to content

Instantly share code, notes, and snippets.

@agibralter
Created February 26, 2009 22:28
Show Gist options
  • Save agibralter/71169 to your computer and use it in GitHub Desktop.
Save agibralter/71169 to your computer and use it in GitHub Desktop.
# ...
Scenario: having current questions in multiple urtaks
Given ...
And b has seen a question in 'cat'
And b has seen a question in 'dog'
When b goes to '/about'
Then b should see the same question in 'cat'
And b should see the same question in 'dog'
# ...
When %r{^.*?go(?:es)? to '(.*)'$} do |page|
visit(page)
end
Given %r{^.*?(?:has|have) seen a question in '([^']*?)'$} do |uri|
visit("/u/#{uri}/responses/new")
response.body.should have_tag('div[class=?]', 'question') do
with_tag('div[class=?]', 'question_text')
with_tag('div[class=?]', 'answers')
end
doc = Hpricot.parse(response.body)
@current_questions ||= {}
@current_questions[uri] = (doc/'div.question'/'div.question_text')
end
Then %r{^.*?should see the same question in '([^']*?)'$} do |uri|
debugger
visit("/u/#{uri}/responses/new")
debugger
response.should have_tag('div[class=?]', 'question') do
debugger
true
Hpricot.parse(response.body)/'div.question'/'div.question_text' #=> #<Hpricot::Elements[{elem <div class="question_text"> "Do you believe in magic no. 27?" </div>}]>
# @current_questions[uri].innerHTML => "Do you believe in magic no. 27?"
with_tag('div[class=?]', 'question_text', @current_questions[uri].innerHTML)
#=>
# Spec::Expectations::ExpectationNotMetError Exception: <"Do you believe in magic no. 27?"> expected but was
# <"Do you believe in magic no. 16?">.
# <false> is not true.
# WTF?? I just parsed the response above and found that div.question_text contains "... magic no. 27?" not "... magic no. 16?"
#
# however; changing the outer block to response.body.should have_tag( ... ) { ... } lets the step pass!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment