|
1 | 1 | require File.join(File.dirname(__FILE__), 'spec_helper') |
2 | 2 |
|
3 | 3 | describe RDF::Query::Variable do |
4 | | - context ".new(:x)" do |
| 4 | + context ".new unbound" do |
5 | 5 | let(:var) {RDF::Query::Variable.new(:x)} |
6 | 6 | subject {var} |
7 | 7 |
|
8 | 8 | it "is named" do |
9 | | - expect(subject.named?).to be_truthy |
| 9 | + expect(subject).to be_named |
10 | 10 | expect(subject.name).to eq :x |
11 | 11 | end |
12 | 12 |
|
|
35 | 35 | expect(subject).to_not be_distinguished |
36 | 36 | end |
37 | 37 |
|
| 38 | + it "can be created as non-distinguished" do |
| 39 | + expect(described_class.new(:x, distinguished: false)).not_to be_distinguished |
| 40 | + end |
| 41 | + |
38 | 42 | it "can be made distinguished" do |
39 | 43 | subject.distinguished = true |
40 | 44 | expect(subject).to be_distinguished |
|
49 | 53 | expect(subject.to_sym).to eq :x |
50 | 54 | end |
51 | 55 |
|
52 | | - |
53 | 56 | it "has no value" do |
54 | 57 | expect(subject.value).to be_nil |
55 | 58 | end |
|
104 | 107 | end |
105 | 108 | end |
106 | 109 |
|
107 | | - context ".new(:x, 123)" do |
| 110 | + context ".new non-distinguished" do |
| 111 | + subject {RDF::Query::Variable.new(:x, RDF::Literal(123))} |
| 112 | + |
| 113 | + it "has a value" do |
| 114 | + expect(subject.value).to eq RDF::Literal(123) |
| 115 | + end |
| 116 | + |
| 117 | + it "is bound" do |
| 118 | + expect(subject).not_to be_unbound |
| 119 | + expect(subject).to be_bound |
| 120 | + expect(subject.variables).to eq({x: subject}) |
| 121 | + expect(subject.bindings).to eq({x: RDF::Literal(123)}) |
| 122 | + end |
| 123 | + |
| 124 | + it "matches only its value" do |
| 125 | + [nil, true, false, RDF::Literal(456)].each do |value| |
| 126 | + expect((subject === value)).to be_falsey |
| 127 | + end |
| 128 | + expect((subject === RDF::Literal(123))).to be_truthy |
| 129 | + end |
| 130 | + |
| 131 | + it "has a string representation" do |
| 132 | + expect(subject.to_s).to eq "?x=123" |
| 133 | + end |
| 134 | + end |
| 135 | + |
| 136 | + context ".new bound" do |
108 | 137 | subject {RDF::Query::Variable.new(:x, RDF::Literal(123))} |
109 | 138 |
|
110 | 139 | it "has a value" do |
|
0 commit comments