How to retrieve <textarea> value in Ruby Cucumber unit testing tool - textarea

I am using the Cucumber unit test tool, and am trying to retrieve the value of a textarea, however I can't get it to work.
This is my code...
page.find(:xpath, "//div[#id='process']/table/tbody/tr/td/div/textarea").value
This is the error I'm getting...
Error: undefined method `value' for nil:NilClass (NoMethodError)
This URL listed below confirms that value is the correct method to retrieve the value:
http://www.w3schools.com/jsref/dom_obj_textarea.asp
Could someone please help me fix this problem.

The nil error indicates that you're not getting the textarea -- find is returning nil. Try a simpler xpath query, or referencing the textarea by name or id.

Related

XPath count not converting to Ruby number

I'm trying to introduce XPath to my Ruby on Rails, Cucumber and Capybara setup for the first time. My code
row_count_on_page = page.find(:xpath, "count(//table[#id='foo']/tbody/tr)")
is resulting in error
undefined method `map' for 10.0:Float
Did you mean? tap (NoMethodError)
The actual XPath part of the code seems to be working correctly because there are exactly ten rows in the body of the table. I don't get how the code can't convert that 10.0 into a Ruby 10 though. What am I doing wrong?
You should do the count outside the method.
row_count_on_page.count
As you are currently using, after the second member of find is evaluated you will have something like:
row_count_on_page = page.find(:xpath, "10.0")
which is not a valid xpath.

undefined method `response_body=' for #<Grape::API:0x007fd8c71f17b8>

I'm writing testing code for api created by grape in rails. There's an error: undefined method `response_body=' for #
does anyone knows the reason and how to fix this? I'll be very thankful for that.
It looks like your code is trying to set the value of response_body, which does not seem like what you want to do. The error is telling you that there is no setter for the attribute...

Stripe RoR - undefined method `encoding' for 1:Fixnum

So I have an if statement. If a customer exists return false. I was trying with an actual customer id but it was throwing an error, I replaced it with a 1. Still getting that error.
if Stripe::Customer.retrieve(1)
throws
undefined method `encoding' for 1:Fixnum
link to the api :
https://stripe.com/docs/api#retrieve_customer
All I had to do was
require "stripe"
... :|
Please check the https://stripe.com/docs/api/ruby#customers
There you can find that, in attributes it takes
id: string
So the code should be
#Stripe::Customer.retrieve({CUSTOMER_ID})
Stripe::Customer.retrieve(1.to_s)
Hope it will work.

Rails NoMethodError in helper although works in debugger

Error:
undefined method `author' for nil:NilClass
In my helper:
def last_updated(group)
g = group.last_updated_version
debugger
g.author.name
end
If I let my last_updated(group) function return group.last_updated_version, the view prints out my object as expected:
#<Assets::Version:0x0000000747af48>
And using the debugger at the point shown above, I can pull out the name
(rdb:1) g.author.name
"Administrator"
But returning group.last_updated_version.author.name results in the error.
Can anyone tell me why group.last_updated_version seems to return my object, but group.last_updated_version.author gives me the nil:NilClass error?
Sorry, silly problem. The helper last_updated() is used in a loop. My method last_updated_version returned nil for some of the group objects it was passed, but not the first. The debugger obviously stops on the first, so it worked in the debugger, but then broke on groups passed after that.

NoMethodError in rails

The extracted source is below :
Showing /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/templates/rescues/diagnostics.erb where line # raised:
private method `gsub' called for #<NoMethodError: undefined method `closed?' for nil:NilClass>
Extracted source (around line #):
RAILS_ROOT: /home/sharath/Desktop/RORWorkspace/ITPLOW1
It was working before installing Sunspot: A Solr-Powered Search Engine for Ruby.
I am working in Ubuntu 10.04.
I'd need to see the full stacktrace to be sure, but this is actually probably an unhelpful HTTP connection error message bubbling up out of RSolr (the library the Sunspot uses for the low-level Solr connection). Is Solr running (i.e., did you run rake sunspot:solr:start)? Can you access http://localhost:8982/solr/admin ?
What's probably happening is you're attempting to do a substitution on some variable which you thought you were initializing, but neglected to give a real value.
For instance, if you had a form where for a Message and one of the the properties you want is the content, you would normally retrieve that information in the controller with
params[:message][:content]
And if you wanted to filter it, you would do something like
params[:message][:content].gsub(/<[^>]*>/,"")
But if the user didn't enter anything into the content field, the params[:message][:content] variable wouldn't be set. Therefore it's null and you're attempting to do nil.gsub

Resources