Debian Codegraph @

rspec-expectations/spec/rspec/matchers/built_in/eql_spec.rb

raw symbols SCIP
1 module RSpec
2 module Matchers
3 RSpec.describe "eql" do
4 it_behaves_like "an RSpec value matcher", :valid_value => 1, :invalid_value => 2 do
5 let(:matcher) { eql(1) }
6 end
7
8 it "is diffable" do
9 expect(eql(1)).to be_diffable
10 end
11
12 it "matches when actual.eql?(expected)" do
13 expect(1).to eql(1)
14 end
15
16 it "does not match when !actual.eql?(expected)" do
17 expect(1).not_to eql(2)
18 end
19
20 it "describes itself" do
21 matcher = eql(1)
22 matcher.matches?(1)
23 expect(matcher.description).to eq "eql 1"
24 end
25
26 it "provides message, expected and actual on #failure_message" do
27 matcher = eql("1")
28 matcher.matches?(1)
29 expect(matcher.failure_message).to eq "\nexpected: \"1\"\n got: 1\n\n(compared using eql?)\n"
30 end
31
32 it "provides message, expected and actual on #negative_failure_message" do
33 matcher = eql(1)
34 matcher.matches?(1)
35 expect(matcher.failure_message_when_negated).to eq "\nexpected: value != 1\n got: 1\n\n(compared using eql?)\n"
36 end
37
38 # Older versions of Ruby such as less than 1.9 do not have String#encoding available, they are an array of bytes
39 if String.method_defined?(:encoding)
40 context "with String encoding as UTF-16LE" do
41 it "provides message, expected and actual on #failure_message when string encoding is the same" do
42 matcher = eql('abc'.encode('UTF-16LE'))
43 matcher.matches?('def'.encode('UTF-16LE'))
44 expect(matcher.failure_message).to eq "\nexpected: \"abc\"\n got: \"def\"\n\n(compared using eql?)\n"
45 end
46
47 it "matches when actual is BINARY encoding and expected is UTF-8 encoding with the same chars" do
48 expect('abc'.encode('BINARY')).to eq 'abc'.encode('UTF-8')
49 end
50
51 it "provides message, expected and actual with encoding details on #failure_message when string encoding is different" do
52 matcher = eql('abc'.encode('UTF-16LE'))
53 matcher.matches?('abc'.dup.force_encoding('ASCII-8BIT'))
54 expect(matcher.failure_message).to eq "\nexpected: #<Encoding:UTF-16LE> \"abc\"\n got: #<Encoding:ASCII-8BIT> \"abc\"\n\n(compared using eql?)\n"
55 end
56
57 it "provides message, expected and actual on #negative_failure_message" do
58 matcher = eql('abc'.encode('UTF-16LE'))
59 matcher.matches?('abc'.encode('UTF-16LE'))
60 expect(matcher.failure_message_when_negated).to eq "\nexpected: value != \"abc\"\n got: \"abc\"\n\n(compared using eql?)\n"
61 end
62 end
63 end
64 end
65 end
66 end