Rspec 3.0 support

This commit is contained in:
erwanlr
2014-06-02 22:06:49 +02:00
parent c12b1d0670
commit c8c126d444
55 changed files with 338 additions and 336 deletions

View File

@@ -30,30 +30,30 @@ describe WpItem do
describe '#new' do
context 'with no options' do
its(:wp_content_dir) { should == 'wp-content' }
its(:wp_plugins_dir) { should == 'wp-content/plugins' }
its(:uri) { should be uri }
its(:wp_content_dir) { is_expected.to eq 'wp-content' }
its(:wp_plugins_dir) { is_expected.to eq 'wp-content/plugins' }
its(:uri) { is_expected.to be uri }
end
context 'with :wp_content_dir' do
let(:options) { { wp_content_dir: 'custom' } }
its(:wp_content_dir) { should == 'custom' }
its(:wp_plugins_dir) { should == 'custom/plugins' }
its(:wp_content_dir) { is_expected.to eq 'custom' }
its(:wp_plugins_dir) { is_expected.to eq 'custom/plugins' }
end
context 'with :wp_plugins_dir' do
let(:options) { { wp_plugins_dir: 'c-plugins' } }
its(:wp_content_dir) { should == 'wp-content' }
its(:wp_plugins_dir) { should == 'c-plugins' }
its(:wp_content_dir) { is_expected.to eq 'wp-content' }
its(:wp_plugins_dir) { is_expected.to eq 'c-plugins' }
end
end
describe '#set_options' do
context 'no an allowed option' do
it 'ignores the option' do
wp_item.should_not_receive(:not_allowed=)
expect(wp_item).not_to receive(:not_allowed=)
wp_item.send(:set_options, { not_allowed: 'owned' })
end
@@ -61,7 +61,7 @@ describe WpItem do
context 'allowed option, w/o setter method' do
it 'raises an error' do
wp_item.stub(:allowed_options).and_return([:no_setter])
allow(wp_item).to receive(:allowed_options).and_return([:no_setter])
expect {
wp_item.send(:set_options, { no_setter: 'hello' })
@@ -73,7 +73,7 @@ describe WpItem do
describe '#path=' do
after do
wp_item.path = @path
wp_item.path.should == @expected
expect(wp_item.path).to eq @expected
end
context 'with default variable value' do
@@ -90,8 +90,8 @@ describe WpItem do
context 'whith custom variable values' do
before {
wp_item.stub(:wp_content_dir).and_return('custom-content')
wp_item.stub(:wp_plugins_dir).and_return('plugins')
allow(wp_item).to receive(:wp_content_dir).and_return('custom-content')
allow(wp_item).to receive(:wp_plugins_dir).and_return('plugins')
}
it 'replaces $wp-content$ by custom-content' do
@@ -117,7 +117,7 @@ describe WpItem do
path = 'somedir/somefile.php'
wp_item.path = path
wp_item.uri.should == uri.merge(path)
expect(wp_item.uri).to eq uri.merge(path)
end
end
end
@@ -127,7 +127,7 @@ describe WpItem do
wp_item.name = 'a-name'
other = WpItem.new(uri, name: 'other-name')
wp_item.<=>(other).should === 'a-name'.<=>('other-name')
expect(wp_item.<=>(other)).to be === 'a-name'.<=>('other-name')
end
end
@@ -137,7 +137,7 @@ describe WpItem do
wp_item.name = 'some-name'
other = WpItem.new(uri, name: 'some-name')
wp_item.should == other
expect(wp_item).to eq other
end
end
@@ -146,7 +146,7 @@ describe WpItem do
wp_item.name = 'Test'
other = WpItem.new(uri, name: 'hello')
wp_item.should_not == other
expect(wp_item).not_to eq other
end
end
end
@@ -156,13 +156,13 @@ describe WpItem do
context 'when the :name and :version are the same' do
it 'is ===' do
WpItem.new(uri, options).should === WpItem.new(uri.merge('yo'), options)
expect(WpItem.new(uri, options)).to be === WpItem.new(uri.merge('yo'), options)
end
end
context 'otherwise' do
it 'is not ===' do
WpItem.new(uri, options).should_not === WpItem.new(uri, options.merge(version: '1.0'))
expect(WpItem.new(uri, options)).not_to be === WpItem.new(uri, options.merge(version: '1.0'))
end
end
end

View File

@@ -23,7 +23,7 @@ describe WpPlugin do
let(:options) { { name: 'plugin-name' } }
describe '#forge_uri' do
its('uri.to_s') { should == 'http://example.com/wp-content/plugins/plugin-name/' }
its('uri.to_s') { is_expected.to eq 'http://example.com/wp-content/plugins/plugin-name/' }
end
end

View File

@@ -18,9 +18,9 @@ describe 'WpTheme::Findable' do
wp_theme = WpTheme.send(:find_from_css_link, uri)
if @expected
wp_theme.should be_a WpTheme
expect(wp_theme).to be_a WpTheme
end
wp_theme.should == @expected
expect(wp_theme).to eq @expected
end
context 'when theme is not present' do
@@ -66,9 +66,9 @@ describe 'WpTheme::Findable' do
wp_theme = WpTheme.send(:find_from_wooframework, uri)
if @expected
wp_theme.should be_a WpTheme
expect(wp_theme).to be_a WpTheme
end
wp_theme.should == @expected
expect(wp_theme).to eq @expected
end
context 'when theme is not present' do
@@ -96,7 +96,7 @@ describe 'WpTheme::Findable' do
# Stub all WpTheme::find_from_* to return nil
def stub_all_to_nil
WpTheme.methods.grep(/^find_from_/).each do |method|
WpTheme.stub(method).and_return(nil)
allow(WpTheme).to receive(method).and_return(nil)
end
end
@@ -120,7 +120,7 @@ describe 'WpTheme::Findable' do
it 'returns nil' do
stub_all_to_nil()
WpTheme.find(uri).should be_nil
expect(WpTheme.find(uri)).to be_nil
end
end
@@ -130,12 +130,12 @@ describe 'WpTheme::Findable' do
stub_request(:get, /.+\/the-oracle\/style.css$/).to_return(status: 200)
expected = WpTheme.new(uri, name: 'the-oracle')
WpTheme.stub(:find_from_css_link).and_return(expected)
allow(WpTheme).to receive(:find_from_css_link).and_return(expected)
wp_theme = WpTheme.find(uri)
wp_theme.should be_a WpTheme
wp_theme.should == expected
wp_theme.found_from.should === 'css link'
expect(wp_theme).to be_a WpTheme
expect(wp_theme).to eq expected
expect(wp_theme.found_from).to be === 'css link'
end
end

View File

@@ -29,22 +29,22 @@ describe WpTheme do
let(:theme_path) { 'wp-content/themes/theme-name/' }
describe '#allowed_options' do
its(:allowed_options) { should include :style_url }
its(:allowed_options) { is_expected.to include :style_url }
end
describe '#forge_uri' do
its(:uri) { should == uri.merge(theme_path) }
its(:uri) { is_expected.to eq uri.merge(theme_path) }
end
describe '#style_url' do
its(:style_url) { should == uri.merge(theme_path + '/style.css').to_s }
its(:style_url) { is_expected.to eq uri.merge(theme_path + '/style.css').to_s }
context 'when its already set' do
it 'returns it instead of the default one' do
url = uri.merge(theme_path + '/custom.css').to_s
wp_theme.style_url = url
wp_theme.style_url.should == url
expect(wp_theme.style_url).to eq url
end
end
end

View File

@@ -13,17 +13,19 @@ describe WpTimthumb do
describe '#==' do
context 'when both url are equal' do
it 'returns true' do
WpTimthumb.new(uri, path: 'timtuhumb.php').
should ==
expect(WpTimthumb.new(uri, path: 'timtuhumb.php')).
to eq(
WpTimthumb.new(uri, path: 'timtuhumb.php')
)
end
end
context 'when urls are different' do
it 'returns false' do
WpTimthumb.new(uri, path: 'hello/timtuhumb.php').
should_not ==
expect(WpTimthumb.new(uri, path: 'hello/timtuhumb.php')).
not_to eq(
WpTimthumb.new(uri, path: 'some-dir/timtuhumb.php')
)
end
end
end

View File

@@ -12,10 +12,10 @@ describe WpUser do
describe '#allowed_options' do
[:id, :login, :display_name, :password].each do |sym|
its(:allowed_options) { should include sym }
its(:allowed_options) { is_expected.to include sym }
end
its(:allowed_options) { should_not include :name }
its(:allowed_options) { is_expected.not_to include :name }
end
describe '#uri' do
@@ -29,7 +29,7 @@ describe WpUser do
it 'returns the uri to the auhor page' do
wp_user.id = 2
wp_user.uri.should == uri.merge('?author=2')
expect(wp_user.uri).to eq uri.merge('?author=2')
end
end
end
@@ -37,7 +37,7 @@ describe WpUser do
describe '#to_s' do
after do
subject.id = 1
subject.to_s.should == @expected
expect(subject.to_s).to eq @expected
end
it 'returns @id' do
@@ -67,20 +67,20 @@ describe WpUser do
wp_user.id = 1
other = WpUser.new(uri, id: 3)
wp_user.<=>(other).should === 1.<=>(3)
expect(wp_user.<=>(other)).to be === 1.<=>(3)
end
end
describe '#===, #==' do
context 'when the :id and :login are the same' do
it 'is ===, and ==' do
WpUser.new(uri, id: 1, name: 'yo').should == WpUser.new(uri, id: 1, name: 'yo')
expect(WpUser.new(uri, id: 1, name: 'yo')).to eq WpUser.new(uri, id: 1, name: 'yo')
end
end
context 'when :id and :login are different' do
it 'is not === or ==' do
WpUser.new(uri, id: 1, name: 'yo').should_not == WpUser.new(uri, id: 2, name:'yo')
expect(WpUser.new(uri, id: 1, name: 'yo')).not_to eq WpUser.new(uri, id: 2, name:'yo')
end
end
end

View File

@@ -26,7 +26,7 @@ describe 'WpVersion::Findable' do
fixture = fixtures_dir + dir_name + @fixture
stub_request_to_fixture(url: url, fixture: fixture)
WpVersion.send(method, uri).should == @expected
expect(WpVersion.send(method, uri)).to eq @expected
end
context 'when generator not found' do
@@ -81,7 +81,7 @@ describe 'WpVersion::Findable' do
:find_from_advanced_fingerprinting,
uri, wp_content_dir, wp_plugins_dir, versions_xml
)
version.should == @expected
expect(version).to eq @expected
end
context 'when' do
@@ -108,7 +108,7 @@ describe 'WpVersion::Findable' do
fixture = fixtures_dir + 'readme' + @fixture
stub_request_to_fixture(url: url, fixture: fixture)
WpVersion.send(:find_from_readme, uri).should == @expected
expect(WpVersion.send(:find_from_readme, uri)).to eq @expected
end
context 'when version not found' do
@@ -138,7 +138,7 @@ describe 'WpVersion::Findable' do
fixture = fixtures_dir + 'links_opml' + @fixture
stub_request_to_fixture(url: url, fixture: fixture)
WpVersion.send(:find_from_links_opml, uri).should == @expected
expect(WpVersion.send(:find_from_links_opml, uri)).to eq @expected
end
it 'returns 3.4.2' do
@@ -158,7 +158,7 @@ describe 'WpVersion::Findable' do
# Stub all WpVersion::find_from_* to return nil
def stub_all_to_nil
WpVersion.methods.grep(/^find_from_/).each do |method|
WpVersion.stub(method).and_return(nil)
allow(WpVersion).to receive(method).and_return(nil)
end
end
@@ -170,9 +170,9 @@ describe 'WpVersion::Findable' do
stub_request(:get, /#{uri.to_s}.*/).to_return(status: 0)
version = WpVersion.find(uri, wp_content_dir, wp_plugins_dir, version_xml)
version.should == @expected
expect(version).to eq @expected
if @expected
version.found_from.should == @found_from
expect(version.found_from).to eq @found_from
end
end
@@ -191,7 +191,7 @@ describe 'WpVersion::Findable' do
it "returns the correct WpVersion" do
stub_all_to_nil()
WpVersion.stub(method).and_return(number)
allow(WpVersion).to receive(method).and_return(number)
@expected = WpVersion.new(uri, number: number)
@found_from = found_from

View File

@@ -24,7 +24,7 @@ describe WpVersion do
describe '#allowed_options' do
[:number, :found_from].each do |sym|
its(:allowed_options) { should include sym }
its(:allowed_options) { is_expected.to include sym }
end
end