Skip to content

Commit

Permalink
Upgrade rspec to 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Aug 8, 2016
1 parent 4d4e4a3 commit 988cbe1
Show file tree
Hide file tree
Showing 16 changed files with 217 additions and 216 deletions.
2 changes: 1 addition & 1 deletion mida.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
spec.add_dependency('addressable', '~> 2.4')
spec.add_development_dependency "bundler", "~> 1.6"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", "~> 2.99.0"
spec.add_development_dependency "rspec", "~> 3.1"
end
16 changes: 8 additions & 8 deletions spec/datatype/boolean_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@

it '#parse should raise an exception if a invalid text passed' do
test = lambda {Mida::DataType::Boolean.parse('example')}
test.should raise_error(ArgumentError)
expect(test).to raise_error(ArgumentError)
end

it '#parse should raise an exception if value is empty' do
test = lambda {Mida::DataType::Boolean.parse('')}
test.should raise_error(ArgumentError)
expect(test).to raise_error(ArgumentError)
end

it '#parse should return true for "True" whatever the case' do
['true', 'True', 'TRUE', 'tRUE'].each do |true_text|
Mida::DataType::Boolean.parse(true_text).should be_true
expect(Mida::DataType::Boolean.parse(true_text)).to be_truthy
end
end

it '#parse should return false for "False" whatever the case' do
['false', 'False', 'FALSE', 'fALSE'].each do |false_text|
Mida::DataType::Boolean.parse(false_text).should be_false
expect(Mida::DataType::Boolean.parse(false_text)).to be_falsey
end
end

it '#to_s should return proper string representation of boolean' do
Mida::DataType::Boolean.parse('fALSE').to_s.should == 'False'
Mida::DataType::Boolean.parse('tRUE').to_s.should == 'True'
expect(Mida::DataType::Boolean.parse('fALSE').to_s).to eq('False')
expect(Mida::DataType::Boolean.parse('tRUE').to_s).to eq('True')
end

it '! should negate as if a TrueClass/FalseClass' do
true_boolean = Mida::DataType::Boolean.parse('true')
false_boolean = Mida::DataType::Boolean.parse('false')

(!true_boolean).should be_false
(!false_boolean).should be_true
expect(!true_boolean).to be_falsey
expect(!false_boolean).to be_truthy
end

end
6 changes: 3 additions & 3 deletions spec/datatype/enumeration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ class BookType < Mida::DataType::Enumeration

it '#parse should raise an exception if an invalid url passed' do
test = lambda {BookType.parse('http://example.com/hardback')}
test.should raise_error(ArgumentError)
expect(test).to raise_error(ArgumentError)
end

it '#parse should raise an exception if value is empty' do
test = lambda {BookType.parse('')}
test.should raise_error(ArgumentError)
expect(test).to raise_error(ArgumentError)
end

it '#parse should accept a valid value' do
url_text = 'http://example.com/ebook'
url = BookType.parse(url_text)
url.to_s.should == url_text
expect(url.to_s).to eq(url_text)
end

end
6 changes: 3 additions & 3 deletions spec/datatype/float_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

it '#parse should raise an exception if not a number' do
test = lambda {Mida::DataType::Float.parse('hello')}
test.should raise_error(ArgumentError)
expect(test).to raise_error(ArgumentError)
end

it '#parse should raise an exception if value is empty' do
test = lambda {Mida::DataType::Float.parse('')}
test.should raise_error(ArgumentError)
expect(test).to raise_error(ArgumentError)
end

it '#parse should accept a valid number' do
float_text = '3.14'
float = Mida::DataType::Float.parse(float_text)
float.to_s.should == float_text
expect(float.to_s).to eq(float_text)
end

end
18 changes: 9 additions & 9 deletions spec/datatype/generic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ def initialize(value)

it "should provide access to the underlying type's methods" do
number = Number.new('2.34')
number.floor.should == 2
expect(number.floor).to eq(2)
end

it '#to_s should use the underlying types #to_s method' do
number = Number.parse('2.34')
number.to_s.should == '2.34'
expect(number.to_s).to eq('2.34')
end

it '#to_yaml should provide a yaml representation of the items #to_s method' do
number = Number.parse('2.34')
number.to_yaml.should =~ /---\s+['"]2.34['"]\n/
expect(number.to_yaml).to match(/---\s+['"]2.34['"]\n/)
end

it '#== should match against underlying type, string representation and self' do
number = Number.new('2.34')
(number == 2.34).should be_true
(number == '2.34').should be_true
(number == number).should be_true
expect(number == 2.34).to be_truthy
expect(number == '2.34').to be_truthy
expect(number == number).to be_truthy

(number == 2.44).should be_false
(number == '2.44').should be_false
(number == Number.new('2.44')).should be_false
expect(number == 2.44).to be_falsey
expect(number == '2.44').to be_falsey
expect(number == Number.new('2.44')).to be_falsey
end

end
8 changes: 4 additions & 4 deletions spec/datatype/integer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

it '#parse should raise an exception if not a number' do
test = lambda {Mida::DataType::Integer.parse('hello')}
test.should raise_error(ArgumentError)
expect(test).to raise_error(ArgumentError)
end

it '#parse should raise an exception if not an integer' do
test = lambda {Mida::DataType::Integer.parse('3.14')}
test.should raise_error(ArgumentError)
expect(test).to raise_error(ArgumentError)
end

it '#parse should raise an exception if value is empty' do
test = lambda {Mida::DataType::Integer.parse('')}
test.should raise_error(ArgumentError)
expect(test).to raise_error(ArgumentError)
end

it '#parse should accept a valid number' do
integer_text = '3'
integer = Mida::DataType::Integer.parse(integer_text)
integer.to_s.should == integer_text
expect(integer.to_s).to eq(integer_text)
end

end
6 changes: 3 additions & 3 deletions spec/datatype/iso8601date_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

it '#parse should raise an exception if invalid date format' do
test = lambda {Mida::DataType::ISO8601Date.parse('27th August 2009')}
test.should raise_error(ArgumentError)
expect(test).to raise_error(ArgumentError)
end

it '#parse should raise an exception if value is empty' do
test = lambda {Mida::DataType::ISO8601Date.parse('')}
test.should raise_error(ArgumentError)
expect(test).to raise_error(ArgumentError)
end

context 'when passed a valid date' do
Expand All @@ -19,7 +19,7 @@
end

it '#to_s should return the date as an rfc822 text string' do
@date.to_s.should == "Thu, 27 Aug 2009 01:13:04 +0510"
expect(@date.to_s).to eq("Thu, 27 Aug 2009 01:13:04 +0510")
end

end
Expand Down
6 changes: 3 additions & 3 deletions spec/datatype/number_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

it '#parse should raise an exception if not a number' do
test = lambda {Mida::DataType::Number.parse('hello')}
test.should raise_error(ArgumentError)
expect(test).to raise_error(ArgumentError)
end

it '#parse should raise an exception if value is empty' do
test = lambda {Mida::DataType::Number.parse('')}
test.should raise_error(ArgumentError)
expect(test).to raise_error(ArgumentError)
end

it '#parse should accept a valid number' do
num_text = '3.14'
num = Mida::DataType::Number.parse(num_text)
num.to_s.should == num_text
expect(num.to_s).to eq(num_text)
end

end
4 changes: 2 additions & 2 deletions spec/datatype/text_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

it '#parse should accept an empty string' do
text = Mida::DataType::Text.parse('')
text.should == ''
expect(text).to eq('')
end

it '#parse should return the input value' do
test_text = 'Some text'
text = Mida::DataType::Text.parse(test_text)
text.should == test_text
expect(text).to eq(test_text)
end

end
8 changes: 4 additions & 4 deletions spec/datatype/url_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@

it '#parse should raise an exception if a bad url passed' do
test = lambda {Mida::DataType::URL.parse('example.com')}
test.should raise_error(ArgumentError)
expect(test).to raise_error(ArgumentError)
end

it '#parse should raise an exception if value is empty' do
test = lambda {Mida::DataType::URL.parse('')}
test.should raise_error(ArgumentError)
expect(test).to raise_error(ArgumentError)
end

it '#parse should accept a valid url' do
url_text = 'http://example.com/test/'
url = Mida::DataType::URL.parse(url_text)
url.to_s.should == url_text
expect(url.to_s).to eq(url_text)
end

it '#parse should accept a valid url with special characters' do
url_text = 'http://example.com/übergangslösung'
url = Mida::DataType::URL.parse(url_text)
url.to_s.should == ::Addressable::URI.encode(url_text)
expect(url.to_s).to eq(::Addressable::URI.encode(url_text))
end
end
44 changes: 22 additions & 22 deletions spec/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_parsing(md, vocabulary, expected_results)
end

def test_to_h(item, expected_result)
item.to_h.should == expected_result
expect(item.to_h).to eq(expected_result)
end

def test_properties(item, expected_result)
Expand All @@ -25,7 +25,7 @@ def match_array_legacy(value_array, expected_results)
if element.is_a?(Mida::Item)
test_properties(element, expected_results[i])
else
element.should == expected_results[i]
expect(element).to eq(expected_results[i])
end
end
end
Expand Down Expand Up @@ -56,22 +56,22 @@ def match_array_legacy(value_array, expected_results)

it '#each should pass each item to the block' do
item_num = 0
@md.each {|item| item.should == @md.items[item_num]; item_num += 1}
@md.each {|item| expect(item).to eq(@md.items[item_num]); item_num += 1}
end

it 'should have access to the Enumerable mixin methods such as #find' do
review = @md.find {|item| item.type == 'http://data-vocabulary.org/Review'}
review.type.should == 'http://data-vocabulary.org/Review'
review.properties['itemreviewed'].should == ["Romeo Pizza"]
expect(review.type).to eq('http://data-vocabulary.org/Review')
expect(review.properties['itemreviewed']).to eq(["Romeo Pizza"])

organization = @md.find {|item| item.type == 'http://data-vocabulary.org/Organization'}
organization.type.should == 'http://data-vocabulary.org/Organization'
organization.properties['name'].should == ["An org name"]
expect(organization.type).to eq('http://data-vocabulary.org/Organization')
expect(organization.properties['name']).to eq(["An org name"])
end

it 'should not re-parse a nokogiri document' do
md = Mida::Document.new(@nokogiri_document)
md.instance_variable_get(:@doc).object_id.should == @nokogiri_document.object_id
expect(md.instance_variable_get(:@doc).object_id).to eq(@nokogiri_document.object_id)
end
end

Expand Down Expand Up @@ -123,14 +123,14 @@ class Review < Mida::Vocabulary

it '#search should be able to match against items without an itemtype' do
items = @md.search(%r{^$})
items.size.should == 1
items[0].properties['name'].should == ['An org name']
expect(items.size).to eq(1)
expect(items[0].properties['name']).to eq(['An org name'])
end

it '#search should be able to match against items with an itemtype' do
items = @md.search(%r{^.+$})
items.size.should == 1
items[0].type.should == 'http://data-vocabulary.org/Review'
expect(items.size).to eq(1)
expect(items[0].type).to eq('http://data-vocabulary.org/Review')
end
end

Expand Down Expand Up @@ -159,7 +159,7 @@ class Review < Mida::Vocabulary
end

it 'should return all the itemscopes' do
@md.items.size.should == 2
expect(@md.items.size).to eq(2)
end

it 'should give the type of each itemscope if none specified' do
Expand All @@ -172,8 +172,8 @@ class Review < Mida::Vocabulary
itemscope_names[item.type] += 1
end

itemscope_names.size.should eq 2
itemscope_names.each { |name, num| num.should == 1 }
expect(itemscope_names.size).to eq 2
itemscope_names.each { |name, num| expect(num).to eq(1) }
end


Expand Down Expand Up @@ -227,19 +227,19 @@ class Review < Mida::Vocabulary
end

it 'should not match itemscopes with different names' do
@md.search(%r{nothing}).size.should == 0
expect(@md.search(%r{nothing}).size).to eq(0)
end

it 'should find the correct number of itemscopes' do
@md.items.size.should == 1
expect(@md.items.size).to eq(1)
end

it 'should return the correct number of itemscopes' do
vocabularies = [
%r{http://data-vocabulary.org/Product},
%r{http://data-vocabulary.org/Review-aggregate}
]
vocabularies.each {|vocabulary| @md.search(vocabulary).size.should == 1}
vocabularies.each {|vocabulary| expect(@md.search(vocabulary).size).to eq(1)}

end

Expand Down Expand Up @@ -296,16 +296,16 @@ class Review < Mida::Vocabulary
%r{http://data-vocabulary.org/Product} => 1,
%r{http://data-vocabulary.org/Review-aggregate} => 1
}
vocabularies.each {|vocabulary, num| @md.search(vocabulary).size.should == num}
vocabularies.each {|vocabulary, num| expect(@md.search(vocabulary).size).to eq(num)}
end

it 'should return the correct number of items' do
@md.items.size.should == 2
expect(@md.items.size).to eq(2)
end

context "when no vocabulary specified or looking at the outer vocabulary" do
it 'should return all the properties from the text with the correct values' do
pending("get the contains: feature working")
skip("get the contains: feature working")
expected_result = {
type: 'http://data-vocabulary.org/Product',
properties: {
Expand All @@ -321,7 +321,7 @@ class Review < Mida::Vocabulary
}
}

@md.search('http://data-vocabulary.org/Product').first.should == expected_result
expect(@md.search('http://data-vocabulary.org/Product').first).to eq(expected_result)
end
end
end
Loading

0 comments on commit 988cbe1

Please sign in to comment.