0

I need to check text message inside toastr-rails. But in my tests, text isn't show. How to run rspec with js? Or I should do something else?

scenario "#email" do
  fill_in "user_email", with: "johndoe@mail.com"
  click_on "Save"
  expect(page).to have_content 'Your account has been updated successfully'
end

My message template(toastr)

<% unless flash.empty? %>
<script type="text/javascript">
    <% flash.each do |f| %>
    <% type = f[0].to_s.gsub('alert', 'error').gsub('notice', 'info') %>
    toastr['<%= type %>']('<%= f[1] %>');
    <% end %>
</script>
dip
  • 1
  • 1

1 Answers1

0

I had the same issue and this is how it worked

  1. Use the Capybara.javascript_driver in your scenario:
scenario "#email", :js => true do
  fill_in "user_email", with: "johndoe@mail.com"
  click_on "Save"
  expect(page).to have_content 'Your account has been updated successfully'
end
  1. Check for message inside the div that toastr generates

within(".toast-info") do expect(page).to have_text('Your account has been updated successfully') end