Skip to content

Commit 9b2026e

Browse files
author
Tom Johnson
committed
Update to use a new shared_example style
This refactors all the shared example sets to use the newer `shared_example` style definitions. To use these example sets do, e.g.: it_behaves_like 'an RDF::Enumerable' This also shifts from the pattern of defining `@instance_variables` in a `before` block to using `let` (We might consider using shared example arguments instead).
1 parent b082691 commit 9b2026e

15 files changed

Lines changed: 895 additions & 904 deletions

lib/rdf/spec/countable.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
require 'rdf/spec'
22

3-
module RDF_Countable
4-
extend RSpec::SharedContext
3+
RSpec.shared_examples 'an RDF::Countable' do
54
include RDF::Spec::Matchers
65

7-
before :each do
8-
raise '+@countable+ must be defined in a before(:each) block' unless instance_variable_get('@countable')
6+
before do
7+
raise 'countable must be set with `let(:countable)' unless
8+
defined? countable
99

1010
@statements = RDF::Spec.quads
1111

12-
if @countable.empty?
13-
if (@countable.writable? rescue false)
14-
@countable.insert_statements(@statements)
15-
elsif @countable.respond_to?(:<<)
16-
@statements.each { |statement| @countable << statement }
12+
if countable.empty?
13+
if (countable.writable? rescue false)
14+
countable.send(:insert_statements, @statements)
15+
elsif countable.respond_to?(:<<)
16+
@statements.each { |statement| countable << statement }
1717
else
18-
raise "+@countable+ must respond to #<< or be pre-populated with the statements in #{RDF::Spec::TRIPLES_FILE} in a before(:each) block"
18+
raise "+countable+ must respond to #<< or be pre-populated with the" \
19+
"statements in #{RDF::Spec::TRIPLES_FILE} in a before block"
1920
end
2021
end
2122
end
2223

2324
describe RDF::Countable do
24-
subject {@countable}
25+
subject {countable}
2526

2627
it {should respond_to(:empty?)}
2728
it {should_not be_empty}

lib/rdf/spec/durable.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
# File.delete('test.db') if File.exists?('test.db')
1515
# end
1616
#
17-
# include RDF_Repository
17+
# it_behaves_like 'an RDF::Repository'
1818
# end
1919
#end
20-
module RDF_Durable
21-
extend RSpec::SharedContext
20+
RSpec.shared_examples 'an RDF::Durable' do
2221
include RDF::Spec::Matchers
2322

2423
before :each do
25-
raise '+@load_durable+ must be defined in a before(:each) block' unless instance_variable_get('@load_durable')
24+
raise '+@load_durable+ must be defined in a before(:each) block' unless
25+
instance_variable_get('@load_durable')
2626
end
2727

2828
describe RDF::Durable do

0 commit comments

Comments
 (0)