Sha256: 7637e3a64a3c48df7ae64cc55a8b1fc9b49369baf0eadb179b8dca02e4fa3522
Contents?: true
Size: 1.59 KB
Versions: 18
Compression:
Stored size: 1.59 KB
Contents
RSpec.describe Rack::Tracker do let(:escaper) do Class.new { include Rack::Tracker::JavaScriptHelper }.new end subject { escaper } # Instance methods are mixed in it { should respond_to :escape_javascript } it { should respond_to :j } context 'with plain values' do it 'should return untouched values' do expect(escaper.j('Hello')).to eq 'Hello' end end # The following is a RSpec port of original rails's test suite for #j method. # https://github.com/rails/rails/blob/master/actionview/test/template/javascript_helper_test.rb describe '#escape_javascript' do # Simple matcher to shorten specs matcher :escape do |value| match do |actual| raise ArgumentError, 'macther syntax is escape("some value").to("expected value")' unless @expected actual.j(value) == @expected end # Syntactic sugar for matcher chain :to do |to| @expected = to self end end it { should escape(nil).to '' } it { should escape(%(This "thing" is really\n netos')).to %(This \\"thing\\" is really\\n netos\\') } it { should escape(%(backslash\\test)).to %(backslash\\\\test) } it { should escape(%(dont </close> tags)).to %(dont <\\/close> tags) } it { should escape(%(unicode \342\200\250 newline).force_encoding(Encoding::UTF_8).encode!).to %(unicode 
 newline) } it { should escape(%(unicode \342\200\251 newline).force_encoding(Encoding::UTF_8).encode!).to %(unicode 
 newline) } it 'works with symbols' do expect(subject).to escape(:dimension1).to 'dimension1' end end end
Version data entries
18 entries across 18 versions & 1 rubygems