Failure on all Rspec Assertions

36 views
Skip to first unread message

mark lane

unread,
Feb 13, 2017, 5:02:06 PM2/13/17
to Cucumber and Cheese, mark lane
When running the first x3 scenarios my Rspec assertions don't seem to be working. I can't work out why! Please could somebody assist. I would be eternally grateful!

The errors are as follows:


1.
my steps for this is..

Then I should see "Thank you for adopting a puppy!"
Then(/^I should see "([^"]*)"$/) do |expected|
expect.(@broswer.text).to include expected
end

get these errors


ArgumentError: You must pass either an argument or a block to `expect`.
./features/step_definitions/adopting_puppy_steps.rb:40:in `/^I should see "([^"]*)"$/'
./features/adopting_puppies.feature:18:in `Then I should see "Thank you for adopting a puppy!"'

ArgumentError: You must pass either an argument or a block to `expect`.
./features/step_definitions/adopting_puppy_steps.rb:40:in `/^I should see "([^"]*)"$/'
./features/adopting_puppies.feature:32:in `Then I should see "Thank you for adopting a puppy!"'

2.my steps are

And I should see "$34.95" as the subtotal for line item 1
And I should see "$34.95" as the cart total

And(/^I should see "\$34\.95" as the subtotal for line item (\d+)$/) do |subtotal, line_item|
row = (line_item.to_i - 1) * 6
expect(@browser.table(:index => 0)[row][3].text).to eql subtotal
end



error
Cucumber::ArityMismatchError: Your block takes 2 arguments, but the Regexp matched 1 argument.
features/step_definitions/adopting_puppy_steps.rb:59:in `/^I should see "\$34\.95" as the subtotal for line item (\d+)$/'
./features/adopting_puppies.feature:39:in `And I should see "$34.95" as the subtotal for line item 1'

Željko Filipin

unread,
Feb 14, 2017, 4:31:17 AM2/14/17
to mark lane, Cucumber and Cheese, mark lane
On Mon, Feb 13, 2017 at 11:02 PM, mark lane <markla...@gmail.com> wrote:
expect.(@broswer.text).to include expected

The problem is trailing dot after expect. Should be like this:

expect(@broswer.text).to include expected
Željko

mark lane

unread,
Feb 14, 2017, 5:01:31 AM2/14/17
to Cucumber and Cheese, markla...@gmail.com, markla...@hotmail.com
Thanks a lot. I was pulling my hair out ! :)

Do you have a view on the second issue? it seems like it it is expected x2 parameters but is only getting one although x2 are mentioned?

Željko Filipin

unread,
Feb 14, 2017, 8:03:25 AM2/14/17
to mark lane, Cucumber and Cheese, mark lane
On Mon, Feb 13, 2017 at 11:02 PM, mark lane <markla...@gmail.com> wrote:
And(/^I should see "\$34\.95" as the subtotal for line item (\d+)$/) do |subtotal, line_item|
Cucumber::ArityMismatchError: Your block takes 2 arguments, but the Regexp matched 1 argument.

You have to put subtotal into parenthesis, for example:

^I should see ("\$34\.95") as the subtotal for line item (\d+)$

Željko

mark lane

unread,
Feb 14, 2017, 8:26:27 AM2/14/17
to Cucumber and Cheese, markla...@gmail.com, markla...@hotmail.com
I will try both of these tonight when I get home. Thank you so much for your help

mark lane

unread,
Feb 14, 2017, 3:27:05 PM2/14/17
to Cucumber and Cheese, markla...@gmail.com, markla...@hotmail.com
I tried and both answers you said were great (thanks again) but now I am getting
NoMethodError: undefined method `text' for nil:NilClass
./features/step_definitions/adopting_puppy_steps.rb:40:in `/^I should see "([^"]*)"$/'
./features/adopting_puppies.feature:18:in `Then I should see "Thank you for adopting a puppy!"'

Feature = Then I should see "Thank you for adopting a puppy!"

Line 40 =

Then(/^I should see "([^"]*)"$/) do |expected|
  expect(@broswer.text).to include expected
end

Carlos GZ

unread,
Feb 14, 2017, 3:47:49 PM2/14/17
to mark lane, Cucumber and Cheese, markla...@hotmail.com
It looks to me as if you've spelt @browser incorrectly, which why you're getting the NoMethodError for text.

mark lane

unread,
Feb 14, 2017, 4:09:08 PM2/14/17
to Cucumber and Cheese, markla...@gmail.com, markla...@hotmail.com
ah great thanks. new error though...

RSpec::Expectations::ExpectationNotMetError: expected "Home of the Happy Puppy\nAdopt a Puppy\nLearn\nAnimal Shelters\nClassifieds\nMessage Boards\nPet New...ils\nName\nAddress\nEmail\nPay type\nSelect a payment method\nCheck\nCredit card\nPurchase order\n " to include "Thank you for adopting a puppy!"
Diff:
@@ -1,2 +1,19 @@
-Thank you for adopting a puppy!
+Home of the Happy Puppy
+Adopt a Puppy
+Learn
+Animal Shelters
+Classifieds
+Message Boards
+Pet News
+Home of the Happy Puppy
+Please Enter Your Details
+Name
+Address
+Email
+Pay type
+Select a payment method
+Check
+Credit card
+Purchase order

./features/step_definitions/adopting_puppy_steps.rb:40:in `/^I should see "([^"]*)"$/'
./features/adopting_puppies.feature:18:in `Then I should see "Thank you for adopting a puppy!"'

I checked the page and it definitely puts the correct text up.. 

Carlos GZ

unread,
Feb 15, 2017, 11:05:43 AM2/15/17
to mark lane, Cucumber and Cheese, mark lane
It would appear your test isn't completing the adoption process, otherwise you'd see 
"Home of the Happy Puppy
Adopt a Puppy
Learn
Animal Shelters
Classifieds
Message Boards
Pet News
Home of the Happy Puppy
Thank you for adopting a puppy!
Puppy List
Brook
Golden Retriever
Female
Hanna
Labrador Retriever Mix
Female
Maggie Mae
Border Colie Mix
Female
Ruby Sue
Pit Bull Terrier
Female

← Previous 1 2 3 Next →
 "

mark lane

unread,
Feb 15, 2017, 2:08:13 PM2/15/17
to Cucumber and Cheese, markla...@gmail.com, markla...@hotmail.com
Hi 

Thanks for your reply. I have watched the script and it brings up the page with the text on it but it doesn't seem to see it..I can't work it out!

mark lane

unread,
Feb 16, 2017, 4:54:19 PM2/16/17
to Cucumber and Cheese
I've checked this again tonight and it seems the page is closed very quickly. Any ideas maybe to debug this. I'm am using ruby mine. Does it have this ability?

Spartan Test Solutions

unread,
Feb 17, 2017, 3:54:55 AM2/17/17
to mark lane, Cucumber and Cheese
Hi Mark

You may want to look at using a wait_until as described here: https://github.com/cheezy/page-object/wiki/Ajax-Calls
With regards to RubyMine you can set a breakpoint against the line of code you want to inspect and then click on the small green bug icon rather than the play button and it should stop at that point.
Screen Shot 2017-02-17 at 08.53.03.png
Reply all
Reply to author
Forward
0 new messages