Skip to main content

Posts

Showing posts from March, 2019

How many ways to choose a radio button in capybara?

  Couple of ways to choose radio options in capybara. All the below options were mostly i tried from different sources. It might helps you.             find('label[for="for_element"]').click                         find('label', text: "for_element").click             find(:css, "css_value[value='#{1}']").set(true)             choose('Name1', :visible => false)             choose('Name1', visible: false)             orig_value = find("#submit_requirements_crawl_type_1", visible: false).value             choose(option: orig_value)               ...

Testing action mailers in ruby on rails

Action mailers are the part of the rails applications to ensure that mailers working as expected. In this tutorial testing action mailers with capybara . Reset password mailer is taking an example for the testing. Generally, we sent a reset token with the mailer. First, we should create an reset token for mail. reset_token = User.find_by_email(email).reset_password reset_password is method in user model to generate unique token for the each user. Email parameter was the current register user. Now, we should trigger mail to the user with reset token and current user email. ClientMailer.send_welcome_email(email, reset_token).deliver_now This line will send an email to user. The mail contains a url with unique password reset token. Once user click on password reset button in mailer it will take to the password reset page. Once mailer triggers it will store in ActionMailer::Base.deliveries. So, it should not be empty. ActionMailer::Base.deliveries.empty?.should be_false...