cucumber does not recognize my steps - ruby-on-rails

Feature: Home page
As a HR manager of a company I am visiting the digipresent app for the first time
I want to be welcomed with a greeting
Scenario: User sees the welcome message
When: he goes to home page
Then: he should see the welcome message
This file is named as features/home_page.feature
When (/^he goes to the home page$/) do
visit root_path
end
Then (/^he should see the welcome message$/)do
expect(page).to have_content("Welcome to Present")
end
This file is present as features/step_definitions/home_page_steps.rb
$cucumber --require features features/home_page.feature when I do this, the steps are not getting recognised.
Feature: Home page
As a HR manager of a company I am visiting the digipresent app for the first time
I want to be welcomed with a greeting
Scenario: User sees the welcome message # features/home_page.feature:5
When: he goes to home page
Then: he should see the welcome message
1 scenario (1 passed)
0 steps
0m0.023s

There is no semicolon after when and then
Scenario: User sees the welcome message
When he goes to home page
Then he should see the welcome message
This should work

Related

Why does my registration for Mean.JS not stay logged in?

When I refresh the page, I get logged out.
https://blooming-plateau-98618.herokuapp.com/
Sorry to make you register to see the error. It's just a fresh install of MeanJS https://github.com/meanjs/generator-meanjs
I get no errors when I "inspect page" and hit "console." I also am not seeing anything in the heroku logs.
I found out the error was with beautify'ing the code. It separated this important line
var user = {{user | json | safe}};

Rspec/capybara - simulate switch from Online to offline within a test (webkit driver)

I have a ruby on Rails 4 app.
A user loads a page (called deal_page) then he clicks on a button which loads a Rails UJS modal message.
If he is online WHEN he clicks the button, I show a message using javascript offline status recognition (inside the Rails UJS ajax event).
on('ajax:error',function(event,xhr, status, error){
var isOnLine = navigator.onLine;
event.preventDefault();
if (isOnLine) {
//do stuff }
else {
// for disconnected users WHEN triggering call to server, invite to reconnect
var msg;
msg = Messenger().post({
message: "You lost internet,You need to be connected"
});
}
});
I want to test in rspec/capybara (I use webkit driver) that the right content ("You need to be connected. Please connect and try again") is displayed in that case in my feature test.
context "As signed-in visitor who is OFFLINE line when he clicks on the area triggering the modal" do
it "displays the right message " do
visit deal_page_path(deal)
# HOW TO ASSERT THAT THE USER LOSES HIS INTERNET CONNECTION
# USER GOES OFFLINE
first("a#button").click
within('ul.messenger') do
expect(page).to have_content('You lost internet,You need to be connected')
end
end
end
The complexity is that I can't disconnect him from the beginning of the test as he needs to be connected to load the page visit deal_page_path(deal) but then I want to simulate that he loses the internet connection.
How to achieve this ?
Assuming you're just checking window.naviagtor.onLine to determine whether or not it is on/offline (not depending on any events or anything) and because you're using capybara-webkit (won't work in selenium since FF won't let you overwrite navigator, not sure about poltergeist) you can just overwrite window.navigator with the result you want to get. You'll also need to generate an error response for your ajax request, which you can do with puffing-billy
page.execute_script "window.navigator = { onLine: false }"

Activity stream testing

I'm building a activity stream feature in my app, all activities are created via controller methods.
When the controller method is successful the activity is recorder to activity table. Since my controller action is invoked via ajax, I tried posting directly from my rspec test.
I tried this :
Net::HTTP.post_form(URI.parse("http://localhost:5000#{inquiry_path}"), { :id=> #user.id, :type => 'Inquiry' })
This is what I see gets posted in my firebug, when making ajax call:
id:55
type:Inquiry
url:/user_inquiry
So I'm asserting whether the activity count has changed :
it "activity count should be changed" do
PublicActivity::Activity.count.should == 1
end
After I'm done with testing that count has changed, I wanted to see the user home page actually displaying the new notification.
But this test fails :
Failure/Error: PublicActivity::Activity.count.should == 1
expected: 1
got: 0 (using ==)
Just in case I put the puts statement in my controller, to check if the call actually reaches the controller :
puts "Hereeee"
I don't see the message getting printed so I guess the request never reaches the controller, why is that?
Am I doing something wrong here, how can I test this?
My test idea was ok except the part where the request didn't arrive to the controller, here is how I solved it (before and it):
page.driver.post("#{inquiry_path}?id=" + #user.id)
it "post request should return the right response code" do
page.driver.status_code.should eql 200
end
Now my requests are arriving to the controller.

Geb + Cucumber: Restart Browser Between Scenarios

I'm using Grails 2.1.1 with Cucumber and Geb. I have an Auth.feature that contains 2 scenarios. One is for authenticating successfully and the other is for testing invalid credentials.
The way I think I have to work this out is to have geb log out the user from the first scenario before it can run the second scenario. This is because my Given step checks to make sure I'm at the login page. After scenario 1 executes, I'm on a Dashboard page.
I guess my question is do I (a) use geb to sign out the valid user before completing the scenario or (b) is there a way to have it start over between scenarios?
Right now, I've implemented (a) and it works just fine. Just want to know if this is optimal.
Here is my feature
Feature: login to system
As a user of the system
I want to log in to the application
so that I can use it
Scenario: login
Given I access the login page
When I enter valid credentials
Then I see the dashboard
Scenario: auth fail
Given I access the login page
When I enter invalid credentials
Then I see appropriate error messages
And here is my Geb steps
Given(~'^I access the login page$') {->
to LoginPage
at LoginPage
}
When(~'^I enter valid credentials$') {
page.add('user_10001#test.com', '10001')
}
Then(~'^I see the dashboard$') {->
at DashboardPage
}
Then(~'^I see an error message on the login page$') { ->
at LoginPage
}
When(~'^I enter invalid credentials$') { ->
page.add('baduser', 'paddpassword')
}
Then(~'^I see appropriate error messages$') { ->
at LoginPage
// check for error message
}
Based on some more research I've done, it looks like there are a few ways to handle this:
Just like I am already doing it, by logging out at the end of a scenario (or you could do it at the beginning
Make logging out its own scenario
In the env.groovy Before hook, add to LogoutPage
Logout using a Background
Add the following line to the After hook in env.groovy:
bindingUpdater.browser.clearCookies()

'Confirmation token is invalid' when testing with Cucumber

I'm trying to get a sign up form working with Devise; I'm testing it with Cucumber.
When a user signs up, I send a confirmation e-mail. Something goes wrong when running my test, though.
This is my scenario:
Scenario: Signing in via confirmation
Given there are the following users:
| email | password | unconfirmed |
| user#ticketee.com | password | true |
And "user#ticketee.com" opens the email with subject "Confirmation instructions"
And they click the first link in the email
Then I should see "Your account was successfully confirmed."
And I should see "Signed in as user#ticketee.com"
However, I get the following error:
expected there to be content "Your account was successfully confirmed. You are now signed in." in "\n Ticketee\n \n\nTicketee\nSign up\n Sign in\nResend confirmation instructions\n\n\n \n 1 error prohibited this user from being saved:\n Confirmation token is invalid\n\n\n Email\n\n \n\n Sign inSign upForgot your password?" (RSpec::Expectations::ExpectationNotMetError)
I guess the important part here is:
1 error prohibited this user from being saved:\n Confirmation token is invalid
I have tested this manually (went to sign up and clicked the confirmation link in the e-mail) and this works fine.. It's only when I test through Cucumber that I get the 'Confirmation token is invalid' message. Anyone know how I can fix this? I'd like to see my tests pass..
Thanks a lot.
EDIT: Steps asked for in the comments:
When /^(?:I|they|"([^"]*?)") opens? the email with subject "([^"]*?)"$/ do |address, subject|
open_email(address, :with_subject => subject)
end
Clicking link:
When /^(?:I|they) click the first link in the email$/ do
click_first_link_in_email
end
I just looked at the confirmation email I got and my e-mail address is parsed as a mailto: link; I changed the first link step to this:
And they follow "Confirm my account" in the email
but that didn't work either.. I'm still getting the invalid token error message.
So.. I wasted two hours on this. I had a typo.
I have the following line:
unconfirmed = attributes.delete("unconfirmed") == "true"
I forgot to put the quotes around true. Without the quotes, the test passes..
Jeez.
Thanks to everyone who put some time in helping me :)

Resources