-
-
Save tlatsas/04c5f12656eb92d1c444b00aca3ce28f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
ruby "2.7.2" | |
gem "rails" | |
gem "capybara", github: "teamcapybara/capybara", branch: "master" | |
gem "rspec-rails" | |
end | |
require "action_controller/railtie" | |
class TestApp < Rails::Application | |
end | |
module ApplicationHelper | |
def no_quotes | |
{ text: "Sample text" } | |
end | |
def quotes | |
{ text: 'Text with "quotes"' } | |
end | |
end | |
require "rspec/rails" | |
require "rspec/autorun" | |
RSpec.describe "rendered view", type: :view do | |
before do | |
inline_view = "<div id=\"main\" data-no-quotes=\"<%= no_quotes.to_json %>\" data-quotes=\"<%= quotes.to_json %>\"></div>" | |
render(inline: inline_view) | |
end | |
it "has a data attribure with JSON data" do | |
expect(rendered).to have_selector("div#main[data-no-quotes='#{no_quotes.to_json}']") | |
end | |
it "has a data attribure with JSON data including quotes" do | |
expect(rendered).to have_selector("div#main[data-quotes='#{quotes.to_json}']") | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.F | |
Failures: | |
1) rendered view has a data attribure with JSON data including quotes | |
Failure/Error: expect(rendered).to have_selector("div#main[data-quotes='#{quotes.to_json}']") | |
expected to find css "div#main[data-quotes='{\"text\":\"Text with \\\"quotes\\\"\"}']" but there were no matches | |
# capybara_have_selector.rb:55:in `block (2 levels) in <main>' | |
Finished in 0.0322 seconds (files took 0.31486 seconds to load) | |
2 examples, 1 failure | |
Failed examples: | |
rspec capybara_have_selector.rb:54 # rendered view has a data attribure with JSON data including quotes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment