|
1 | 1 | require 'rdf/spec' |
2 | 2 |
|
3 | | -module RDF_Transaction |
4 | | - extend RSpec::SharedContext |
| 3 | +# Pass in an instance of RDF::Transaction as follows: |
| 4 | +# |
| 5 | +# it_behaves_like "RDF_Transaction", RDF::Transaction |
| 6 | +shared_examples "RDF_Transaction" do |klass| |
5 | 7 | include RDF::Spec::Matchers |
6 | 8 |
|
7 | | - before :each do |
8 | | - raise '+@transaction+ must be defined in a before(:each) block' unless instance_variable_get('@transaction') |
9 | | - end |
10 | | - |
11 | 9 | describe RDF::Transaction do |
12 | | - #TODO |
| 10 | + subject {klass.new(:context => RDF::URI("name"), :insert => RDF::Graph.new, :delete => RDF::Graph.new)} |
| 11 | + |
13 | 12 | describe "#initialize" do |
14 | | - it "accepts a graph" |
15 | | - it "accepts a context" |
16 | | - it "accepts inserts" |
17 | | - it "accepts deletes" |
18 | | - end |
19 | | - |
20 | | - describe "#graph" do |
21 | | - it "is mutable" |
| 13 | + subject {klass} |
| 14 | + it "accepts a graph" do |
| 15 | + g = double("graph") |
| 16 | + this = subject.new(:graph => g) |
| 17 | + expect(this.graph).to eq g |
| 18 | + end |
| 19 | + |
| 20 | + it "accepts a context" do |
| 21 | + c = double("context") |
| 22 | + this = subject.new(:graph => c) |
| 23 | + expect(this.graph).to eq c |
| 24 | + expect(this.context).to eq c |
| 25 | + |
| 26 | + this = subject.new(:context => c) |
| 27 | + expect(this.graph).to eq c |
| 28 | + expect(this.context).to eq c |
| 29 | + end |
| 30 | + |
| 31 | + it "accepts inserts" do |
| 32 | + g = double("inserts") |
| 33 | + this = subject.new(:insert => g) |
| 34 | + expect(this.inserts).to eq g |
| 35 | + end |
| 36 | + |
| 37 | + it "accepts deletes" do |
| 38 | + g = double("deletes") |
| 39 | + this = subject.new(:delete => g) |
| 40 | + expect(this.deletes).to eq g |
| 41 | + end |
22 | 42 | end |
23 | | - |
24 | | - describe "#deletes" do |
25 | | - it "is mutable" |
| 43 | + |
| 44 | + its(:deletes) {should be_a(RDF::Enumerable)} |
| 45 | + its(:inserts) {should be_a(RDF::Enumerable)} |
| 46 | + it {should be_mutable} |
| 47 | + it {should_not be_readable} |
| 48 | + |
| 49 | + it "does not respond to #load" do |
| 50 | + expect {subject.load("http://example/")}.to raise_error(NoMethodError) |
26 | 51 | end |
27 | | - |
28 | | - describe "#inserts" do |
29 | | - it "is mutable" |
| 52 | + |
| 53 | + it "does not respond to #update" do |
| 54 | + expect {subject.update(RDF::Statement.new)}.to raise_error(NoMethodError) |
30 | 55 | end |
31 | | - |
32 | | - describe "#readable?" do |
33 | | - it "returns false" do |
34 | | - expect(@transaction.readable?).to be_false |
35 | | - end |
| 56 | + |
| 57 | + it "does not respond to #clear" do |
| 58 | + expect {subject.clear}.to raise_error(NoMethodError) |
36 | 59 | end |
37 | | - |
| 60 | + |
38 | 61 | describe "#execute" do |
39 | | - it "deletes statements" |
40 | | - it "inserts statements" |
41 | | - it "calls before_execute" |
42 | | - it "calls after_execute" |
43 | | - it "returns self" |
44 | | - it "does not delete statements on failures" |
45 | | - it "does not insert statements on failures" |
| 62 | + let(:s) {RDF::Statement.new(RDF::URI("s"), RDF::URI("p"), RDF::URI("o"))} |
| 63 | + let(:r) {double("repository")} |
| 64 | + |
| 65 | + it "deletes statements" do |
| 66 | + expect(r).to receive(:delete).with(s) |
| 67 | + expect(r).not_to receive(:insert) |
| 68 | + subject.delete(s) |
| 69 | + subject.execute(r) |
| 70 | + end |
| 71 | + |
| 72 | + it "inserts statements" do |
| 73 | + expect(r).not_to receive(:delete) |
| 74 | + expect(r).to receive(:insert).with(s) |
| 75 | + subject.insert(s) |
| 76 | + subject.execute(r) |
| 77 | + end |
| 78 | + |
| 79 | + it "calls before_execute" do |
| 80 | + expect(subject).to receive(:before_execute).with(r, {}) |
| 81 | + subject.execute(r) |
| 82 | + end |
| 83 | + |
| 84 | + it "calls after_execute" do |
| 85 | + expect(subject).to receive(:after_execute).with(r, {}) |
| 86 | + subject.execute(r) |
| 87 | + end |
| 88 | + |
| 89 | + it "returns self" do |
| 90 | + expect(subject.execute(r)).to eq subject |
| 91 | + end |
46 | 92 | end |
47 | 93 |
|
48 | 94 | describe "#delete_statement" do |
49 | | - it "adds statement to #deletes" |
50 | | - it "does not remove statement from graph" |
| 95 | + let(:s) {RDF::Statement.new(RDF::URI("s"), RDF::URI("p"), RDF::URI("o"))} |
| 96 | + it "adds statement to #deletes" do |
| 97 | + subject.delete(s) |
| 98 | + expect(subject.deletes.to_a).to eq [s] |
| 99 | + end |
51 | 100 | end |
52 | 101 |
|
53 | 102 | describe "#insert_statement" do |
54 | | - it "adds statement to #inserts" |
55 | | - it "does not add statement to graph" |
| 103 | + let(:s) {RDF::Statement.new(RDF::URI("s"), RDF::URI("p"), RDF::URI("o"))} |
| 104 | + it "adds statement to #inserts" do |
| 105 | + subject.insert(s) |
| 106 | + expect(subject.inserts.to_a).to eq [s] |
| 107 | + end |
56 | 108 | end |
57 | | - |
58 | | - it "does not respond to #load" |
59 | | - it "does not respond to #update" |
60 | | - it "does not respond to #clear" |
61 | 109 | end |
62 | 110 | end |
0 commit comments