Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8879369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:56:04+00:00 2026-06-14T19:56:04+00:00

I’m trying to work out the right syntax to have webrat check the contents

  • 0

I’m trying to work out the right syntax to have webrat check the contents of a textarea in a form.

I can check the presence of a textarea with

response.should have_selector('textarea')

but the contains method appears to only check the visible text in the response. There are capybara methods for checking the contents of a textarea, but I’m working on a large existing set of specs for Capybara, which appear to all be in WebRat, and when I try to use Capybara methods like have_field I keep getting the following error:

RSpec::Expectations::ExpectationNotMetError Exception: expected field "textarea" to return something

I’ve found examples that do things like the following:

response.should have_selector('textarea', :content => 'blah')

but strangely this causes by debugger to continue and I haven’t been able to test it effectively as a solution yet.

Any tips or advice on the correct approach much appreciated

here’s the stacktrace I get testing in the debugger

(rdb:1) p response.should have_selector('textarea#article_body_and_extended', :content =>  text)
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/interface.rb:70:in `printf'
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/interface.rb:70:in `print'
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:375:in `print'
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/command.rb:165:in `print'
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/command.rb:183:in `rescue in debug_eval'
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/command.rb:173:in `debug_eval'
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/commands/eval.rb:47:in `block in execute'
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/commands/eval.rb:19:in `run_with_binding'
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/commands/eval.rb:46:in `execute'
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:275:in `one_cmd'
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:261:in `block (2 levels) in process_commands'
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:260:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:260:in `block in process_commands'
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:253:in `catch'
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:253:in `process_commands'
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:173:in `at_line'
(eval):5:in `block in at_line'
<internal:prelude>:10:in `synchronize'
(eval):3:in `at_line'
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug-base19-0.11.25/lib/ruby-debug-base.rb:55:in `at_line'
/home/ubuntu/Documents/hw5/typo/spec/controllers/admin/content_controller_spec.rb:509:in `block (4 levels) in <top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:113:in `instance_eval'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:113:in `block in run'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:253:in `with_around_each_hooks'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:110:in `run'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:378:in `block in run_examples'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:374:in `map'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:374:in `run_examples'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:360:in `run'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `block in run'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `map'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `run'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `block in run'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `map'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `run'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:28:in `map'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:28:in `block in run'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/reporter.rb:34:in `report'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:25:in `run'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in `run'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'F

and then the debugger continues and the check fails:

    text = @article.body + @article_for_merging.body + "\n&lt;<!--more-->&gt;\n" +@article.extended
    debugger
    response.should have_selector('textarea#article_body_and_extended', :content =>  text)

even though when I do a regex on the response body I get a match

(rdb:1) p text
"A content with several datasomething we will merge&lt;<!--more-->&gt;extended content for fun"
(rdb:1) p response.body =~ text
TypeError Exception: type mismatch: String given
(rdb:1) p response.body =~ /text/
218

what I’d really like is a way just to pull that actual content of the textarea out … although I’m getting the sense I should be writing a model spec instead of a controller spec …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:56:05+00:00Added an answer on June 14, 2026 at 7:56 pm

    so I’ve kind of given up on getting this working. I think I tracked down the right syntax as this:

    response.should have_selector('textarea', :name => "article[body_and_extended]",:content =>  text)
    

    where I’ve set text to be the expected content. I spend a good hour checking that I had precisely the text that was in the textarea, but couldn’t make it work – maybe an encoding issue or something. However what does work is this:

        text = @article.body + @article_for_merging.body + "\n&lt;!--more--&gt;\n" +@article.extended+@article_for_merging.extended
        position = response.body =~ /#{Regexp.quote(text)}/
        position.should_not be_nil
    

    so I tempted to move on and come back to this later …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.