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

@@ -25,7 +25,7 @@ describe Browser do
json_expected_vars['max_threads'] ||= 20 # max_thread can not be nil
instance_vars_to_check.each do |variable_name|
browser.send(:"#{variable_name}").should === json_expected_vars[variable_name]
expect(browser.send(:"#{variable_name}")).to be === json_expected_vars[variable_name]
end
end
@@ -50,7 +50,7 @@ describe Browser do
let(:cache_dir) { CACHE_DIR + '/somewhere' }
let(:options) { { cache_dir: cache_dir } }
after { subject.cache_dir.should == cache_dir }
after { expect(subject.cache_dir).to eq cache_dir }
it 'sets @cache_dir' do
@json_expected_vars = json_config_without_proxy
@@ -84,11 +84,11 @@ describe Browser do
describe '::append_params_header_field' do
after :each do
Browser.append_params_header_field(
expect(Browser.append_params_header_field(
@params,
@field,
@field_value
).should === @expected
)).to be === @expected
end
context 'when there is no headers' do
@@ -140,7 +140,7 @@ describe Browser do
browser.user_agent = 'SomeUA'
browser.cache_ttl = 250
browser.merge_request_params(params).should == @expected
expect(browser.merge_request_params(params)).to eq @expected
end
it 'sets the User-Agent header field and cache_ttl' do
@@ -205,12 +205,12 @@ describe Browser do
let(:url) { 'http://example.localhost' }
it 'returns the correct Typhoeus::Request' do
subject.stub(merge_request_params: { cache_ttl: 10 })
allow(subject).to receive_messages(merge_request_params: { cache_ttl: 10 })
request = subject.forge_request(url)
request.should be_a Typhoeus::Request
request.url.should == url
request.cache_ttl.should == 10
expect(request).to be_a Typhoeus::Request
expect(request.url).to eq url
expect(request.cache_ttl).to eq 10
end
end
@@ -225,7 +225,7 @@ describe Browser do
response1 = Browser.get(url)
response2 = Browser.get(url)
response1.body.should == response2.body
expect(response1.body).to eq response2.body
#WebMock.should have_requested(:get, url).times(1) # This one fail, dunno why :s (but it works without mock)
end
end

View File

@@ -17,14 +17,14 @@ describe CacheFileStore do
describe '#storage_path' do
it 'returns the storage path given in the #new' do
@cache.storage_path.should match(/#{cache_dir}/)
expect(@cache.storage_path).to match(/#{cache_dir}/)
end
end
describe '#serializer' do
it 'should return the default serializer : Marshal' do
@cache.serializer.should == Marshal
@cache.serializer.should_not == YAML
expect(@cache.serializer).to eq Marshal
expect(@cache.serializer).not_to eq YAML
end
end
@@ -35,15 +35,15 @@ describe CacheFileStore do
File.new(@cache.storage_path + "/file_#{i}.txt", File::CREAT)
end
count_files_in_dir(@cache.storage_path, 'file_*.txt').should == 6
expect(count_files_in_dir(@cache.storage_path, 'file_*.txt')).to eq 6
@cache.clean
count_files_in_dir(@cache.storage_path).should == 0
expect(count_files_in_dir(@cache.storage_path)).to eq 0
end
end
describe '#read_entry (nonexistent entry)' do
it 'should return nil' do
@cache.read_entry(Digest::SHA1.hexdigest('hello world')).should be_nil
expect(@cache.read_entry(Digest::SHA1.hexdigest('hello world'))).to be_nil
end
end
@@ -51,7 +51,7 @@ describe CacheFileStore do
after :each do
@cache.write_entry(@key, @data, @timeout)
@cache.read_entry(@key).should === @expected
expect(@cache.read_entry(@key)).to be === @expected
end
it 'should get the correct entry (string)' do
@@ -79,7 +79,7 @@ describe CacheFileStore do
storage_dirs << CacheFileStore.new(cache_dir).storage_path
end
storage_dirs.uniq.size.should == 5
expect(storage_dirs.uniq.size).to eq 5
end
end
end

View File

@@ -15,7 +15,7 @@ describe 'WpPlugins::Detectable' do
context 'when no header' do
it 'returns an empty WpPlugins' do
stub_request(:get, url).to_return(status: 200)
subject.send(:from_header, wp_target).should == subject.new
expect(subject.send(:from_header, wp_target)).to eq subject.new
end
end
@@ -25,7 +25,7 @@ describe 'WpPlugins::Detectable' do
after :each do
stub_request(:get, url).to_return(status: 200, headers: headers, body: '')
subject.send(:from_header, wp_target).should == expected
expect(subject.send(:from_header, wp_target)).to eq expected
end
context 'when w3-total-cache detected' do
@@ -66,7 +66,7 @@ describe 'WpPlugins::Detectable' do
context 'when no body' do
it 'returns an empty WpPlugins' do
stub_request(:get, url).to_return(status: 200, body: '')
subject.send(:from_content, wp_target).should == subject.new
expect(subject.send(:from_content, wp_target)).to eq subject.new
end
end
@@ -77,7 +77,7 @@ describe 'WpPlugins::Detectable' do
after :each do
stub_request(:get, url).to_return(status: 200, body: @body)
stub_request(:get, /readme\.txt/i).to_return(status: 404)
subject.send(:from_content, wp_target).should == expected
expect(subject.send(:from_content, wp_target)).to eq expected
end
context 'when w3 total cache detected' do

View File

@@ -38,7 +38,7 @@ describe 'WpTimthumbs::Detectable' do
describe '::passive_detection' do
it 'returns an empty WpTimthumbs' do
subject.passive_detection(wp_target).should == subject.new
expect(subject.passive_detection(wp_target)).to eq subject.new
end
end
@@ -46,7 +46,7 @@ describe 'WpTimthumbs::Detectable' do
after do
targets = subject.send(:targets_items_from_file, file, wp_target)
targets.map { |t| t.url }.should == @expected.map { |t| t.url }
expect(targets.map { |t| t.url }).to eq @expected.map { |t| t.url }
end
context 'when an empty file' do
@@ -71,7 +71,7 @@ describe 'WpTimthumbs::Detectable' do
theme = 'hello-world'
targets = subject.send(:theme_timthumbs, theme, wp_target)
targets.map { |t| t.url }.should == expected_targets_from_theme(theme).map { |t| t.url }
expect(targets.map { |t| t.url }).to eq expected_targets_from_theme(theme).map { |t| t.url }
end
end
@@ -81,7 +81,7 @@ describe 'WpTimthumbs::Detectable' do
after do
targets = subject.send(:targets_items, wp_target, options)
targets.map { |t| t.url }.should == @expected.sort.map { |t| t.url }
expect(targets.map { |t| t.url }).to eq @expected.sort.map { |t| t.url }
end
context 'when no :theme_name' do

View File

@@ -22,13 +22,13 @@ describe 'WpUsers::Detectable' do
describe '::request_params' do
it 'return an empty Hash' do
subject.request_params.should === {}
expect(subject.request_params).to be === {}
end
end
describe '::passive_detection' do
it 'return an empty WpUsers' do
subject.passive_detection(wp_target).should == subject.new
expect(subject.passive_detection(wp_target)).to eq subject.new
end
end
@@ -36,7 +36,7 @@ describe 'WpUsers::Detectable' do
after do
targets = subject.send(:targets_items, wp_target, options)
targets.should == @expected
expect(targets).to eq @expected
end
context 'when no :range' do

View File

@@ -25,7 +25,7 @@ describe 'WpUsers::Output' do
subject.push(@input)
subject.flatten!
subject.remove_junk_from_display_names
subject.should === @expected
expect(subject).to be === @expected
end
it 'should return an empty array' do

View File

@@ -7,7 +7,7 @@ describe 'common_helper' do
after :each do
output = get_equal_string_end(@input)
output.should == @expected
expect(output).to eq @expected
end
it 'returns an empty string' do
@@ -75,7 +75,7 @@ describe 'common_helper' do
describe '#remove_base64_images_from_html' do
after :each do
output = remove_base64_images_from_html(@html)
output.should == @expected
expect(output).to eq @expected
end
it 'removes the valid base64 image' do
@@ -92,7 +92,7 @@ describe 'common_helper' do
describe '#truncate' do
after :each do
output = truncate(@input, @length, @trailing)
output.should == @expected
expect(output).to eq @expected
end
it 'returns nil on no input' do

View File

@@ -15,7 +15,7 @@ describe CustomOptionParser do
if @exception
expect { CustomOptionParser::option_to_symbol(@option) }.to raise_error(@exception)
else
CustomOptionParser::option_to_symbol(@option).should === @expected
expect(CustomOptionParser::option_to_symbol(@option)).to be === @expected
end
end
@@ -100,7 +100,7 @@ describe CustomOptionParser do
parser.add_option(['-v', '--verbose'])
parser.add_option(['--url TARGET_URL'])
parser.symbols_used.sort.should === [:url, :verbose]
expect(parser.symbols_used.sort).to be === [:url, :verbose]
end
context 'parsing' do
@@ -118,7 +118,7 @@ describe CustomOptionParser do
it 'should retrieve the correct argument' do
parser.parse!(['-u', 'iam_the_target'])
parser.results.should === { url: 'iam_the_target' }
expect(parser.results).to be === { url: 'iam_the_target' }
end
end
end
@@ -134,8 +134,8 @@ describe CustomOptionParser do
context 'single option' do
it 'should add the :url option, and retrieve the correct argument' do
parser.symbols_used.should === [:url]
parser.results(['-u', 'target.com']).should === { url: 'target.com' }
expect(parser.symbols_used).to be === [:url]
expect(parser.results(['-u', 'target.com'])).to be === { url: 'target.com' }
end
end
@@ -146,8 +146,8 @@ describe CustomOptionParser do
['--test [TEST_NUMBER]']
])
parser.symbols_used.sort.should === [:test, :url, :verbose]
parser.results(['-u', 'wp.com', '-v', '--test']).should === { test: nil, url: 'wp.com', verbose: true }
expect(parser.symbols_used.sort).to be === [:test, :url, :verbose]
expect(parser.results(['-u', 'wp.com', '-v', '--test'])).to be === { test: nil, url: 'wp.com', verbose: true }
end
end
end

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

View File

@@ -10,7 +10,7 @@ describe Plugin do
subject(:plugin) { Plugin.new(infos) }
let(:infos) { { author: 'John' } }
its(:author) { should === infos[:author] }
its(:author) { is_expected.to be === infos[:author] }
end
end
@@ -26,7 +26,7 @@ describe Plugin do
expect { plugin.register_options(*@options) }.to raise_error(@exception)
else
plugin.register_options(*@options)
plugin.registered_options.sort.should === @expected.sort
expect(plugin.registered_options.sort).to be === @expected.sort
end
end

View File

@@ -23,18 +23,18 @@ describe Plugins do
describe '#new' do
context 'without argument' do
its(:option_parser) { should be_a CustomOptionParser }
its(:option_parser) { is_expected.to be_a CustomOptionParser }
it 'should be an Array' do
plugins.should be_an Array
expect(plugins).to be_an Array
end
end
context 'with an option_parser argument' do
subject(:plugin) { Plugins.new(CustomOptionParser.new('the banner')) }
its(:option_parser) { should be_a CustomOptionParser }
its('option_parser.banner') { should === 'the banner' }
its(:option_parser) { is_expected.to be_a CustomOptionParser }
its('option_parser.banner') { is_expected.to be === 'the banner' }
it 'should raise an eror if the parser is not an instance of CustomOptionParser' do
expect { Plugins.new(OptionParser.new) }.to raise_error('The parser must be an instance of CustomOptionParser, OptionParser supplied')
@@ -48,8 +48,8 @@ describe Plugins do
expect { plugins.register_plugin(@plugin) }.to raise_error(@exception)
else
plugins.register_plugin(@plugin)
plugins.should include(@plugin)
plugins.should === @expected
expect(plugins).to include(@plugin)
expect(plugins).to be === @expected
end
end
@@ -78,11 +78,11 @@ describe Plugins do
plugins.register(*@plugins_to_register)
@plugins_to_register.each do |plugin|
plugins.should include(plugin)
expect(plugins).to include(plugin)
end
# For the correct order
plugins.should === @plugins_to_register
expect(plugins).to be === @plugins_to_register
end
it 'should register 1 plugin' do

View File

@@ -11,7 +11,7 @@ describe GitUpdater do
describe '#is_installed?' do
after :each do
stub_system_command(@git_updater, /^git .* status/, @stub_value)
@git_updater.is_installed?.should === @expected
expect(@git_updater.is_installed?).to be === @expected
end
it 'should return false if the command is not found' do
@@ -28,7 +28,7 @@ describe GitUpdater do
describe '#local_revision_number' do
after :each do
stub_system_command(@git_updater, /^git .* log/, @stub_value)
@git_updater.local_revision_number.should === @expected
expect(@git_updater.local_revision_number).to be === @expected
end
it 'should return 79c01f3' do
@@ -43,14 +43,14 @@ describe GitUpdater do
describe '#update' do
it 'should do nothing xD' do
stub_system_command(@git_updater, /^git .* pull/, 'Already up-to-date.')
@git_updater.update().should === 'Already up-to-date.'
expect(@git_updater.update()).to be === 'Already up-to-date.'
end
end
describe '#has_local_changes?' do
after :each do
stub_system_command(@git_updater, /^git .* diff --exit-code 2>&1/, @stub_value)
@git_updater.has_local_changes?.should === @expected
expect(@git_updater.has_local_changes?).to be === @expected
end
it 'should return true if there are local changes' do
@@ -67,7 +67,7 @@ describe GitUpdater do
describe '#reset_head' do
it 'should reset the local repo' do
stub_system_command(@git_updater, /^git .* reset --hard HEAD/, 'HEAD is now at')
@git_updater.reset_head.should match(/^HEAD is now at/)
expect(@git_updater.reset_head).to match(/^HEAD is now at/)
end
end

View File

@@ -11,7 +11,7 @@ describe SvnUpdater do
describe '#is_installed?' do
after :each do
stub_system_command(@svn_updater, /^svn info/, @stub_value)
@svn_updater.is_installed?.should === @expected
expect(@svn_updater.is_installed?).to be === @expected
end
it 'should return false if the svn command is not found' do
@@ -50,7 +50,7 @@ describe SvnUpdater do
describe '#local_revision_number' do
after :each do
stub_system_command(@svn_updater, /^svn info/, @stub_value)
@svn_updater.local_revision_number.should === @expected
expect(@svn_updater.local_revision_number).to be === @expected
end
it 'should return 399' do
@@ -79,7 +79,7 @@ describe SvnUpdater do
describe '#update' do
it 'should do nothing xD' do
stub_system_command(@svn_updater, /^svn up/, 'At revision 425.')
@svn_updater.update().should === 'At revision 425.'
expect(@svn_updater.update()).to be === 'At revision 425.'
end
end

View File

@@ -6,7 +6,7 @@ describe UpdaterFactory do
describe '#available_updaters_classes' do
after :each do
UpdaterFactory.available_updaters_classes.sort.should === @expected.sort
expect(UpdaterFactory.available_updaters_classes.sort).to be === @expected.sort
end
it 'should return [:GitUpdater, :SvnUpdater]' do

View File

@@ -5,7 +5,7 @@ require 'spec_helper'
describe 'VersionCompare' do
describe '::is_newer_or_same?' do
context 'version checked is newer' do
after { VersionCompare::is_newer_or_same?(@version1, @version2).should be_true }
after { expect(VersionCompare::is_newer_or_same?(@version1, @version2)).to be_truthy }
it 'returns true' do
@version1 = '1.0'
@@ -39,7 +39,7 @@ describe 'VersionCompare' do
end
context 'version checked is older' do
after { VersionCompare::is_newer_or_same?(@version1, @version2).should be_false }
after { expect(VersionCompare::is_newer_or_same?(@version1, @version2)).to be_falsey }
it 'returns false' do
@version1 = '1'
@@ -63,7 +63,7 @@ describe 'VersionCompare' do
end
context 'version checked is the same' do
after { VersionCompare::is_newer_or_same?(@version1, @version2).should be_true }
after { expect(VersionCompare::is_newer_or_same?(@version1, @version2)).to be_truthy }
it 'returns true' do
@version1 = '1'
@@ -78,7 +78,7 @@ describe 'VersionCompare' do
end
context 'version number causes Gem::Version new Exception' do
after { VersionCompare::is_newer_or_same?(@version1, @version2).should be_false }
after { expect(VersionCompare::is_newer_or_same?(@version1, @version2)).to be_falsey }
it 'returns false' do
@version1 = 'a'
@@ -87,7 +87,7 @@ describe 'VersionCompare' do
end
context 'one version number is not set' do
after { VersionCompare::is_newer_or_same?(@version1, @version2).should be_false }
after { expect(VersionCompare::is_newer_or_same?(@version1, @version2)).to be_falsey }
it 'returns false (version2 nil)' do
@version1 = '1'

View File

@@ -18,13 +18,13 @@ describe 'WebSite' do
end
describe "#new" do
its(:url) { should === 'http://example.localhost/' }
its(:url) { is_expected.to be === 'http://example.localhost/' }
end
describe '#url=' do
after :each do
web_site.url = @uri
web_site.url.should === @expected
expect(web_site.url).to be === @expected
end
context 'when protocol or trailing slash is missing' do
@@ -45,30 +45,30 @@ describe 'WebSite' do
describe '#online?' do
it 'should not be considered online if the status code is 0' do
stub_request(:get, web_site.url).to_return(status: 0)
web_site.should_not be_online
expect(web_site).not_to be_online
end
it 'should be considered online if the status code is != 0' do
stub_request(:get, web_site.url).to_return(status: 200)
web_site.should be_online
expect(web_site).to be_online
end
end
describe '#has_basic_auth?' do
it 'should detect that the wpsite is basic auth protected' do
stub_request(:get, web_site.url).to_return(status: 401)
web_site.should have_basic_auth
expect(web_site).to have_basic_auth
end
it 'should not have a basic auth for a 200' do
stub_request(:get, web_site.url).to_return(status: 200)
web_site.should_not have_basic_auth
expect(web_site).not_to have_basic_auth
end
end
describe '#xml_rpc_url' do
it 'returns the xmlrpc url' do
web_site.xml_rpc_url.should === "http://example.localhost/xmlrpc.php"
expect(web_site.xml_rpc_url).to be === "http://example.localhost/xmlrpc.php"
end
end
@@ -77,17 +77,17 @@ describe 'WebSite' do
stub_request(:get, web_site.xml_rpc_url).
to_return(status: 200, body: "XML-RPC server accepts POST requests only")
web_site.should have_xml_rpc
expect(web_site).to have_xml_rpc
end
it 'returns false' do
stub_request(:get, web_site.xml_rpc_url).to_return(status: 200)
web_site.should_not have_xml_rpc
expect(web_site).not_to have_xml_rpc
end
end
describe '#page_hash' do
after { WebSite.page_hash(page).should == Digest::MD5.hexdigest(@expected) }
after { expect(WebSite.page_hash(page)).to eq Digest::MD5.hexdigest(@expected) }
context 'when the page is an url' do
let(:page) { 'http://e.localhost/somepage.php' }
@@ -125,7 +125,7 @@ describe 'WebSite' do
body = 'Hello World'
stub_request(:get, web_site.url).to_return(body: body)
web_site.homepage_hash.should === Digest::MD5.hexdigest(body)
expect(web_site.homepage_hash).to be === Digest::MD5.hexdigest(body)
end
end
@@ -134,19 +134,19 @@ describe 'WebSite' do
stub_request(:any, /.*/).
to_return(status: 404, body: '404 page !')
web_site.error_404_hash.should === Digest::MD5.hexdigest('404 page !')
expect(web_site.error_404_hash).to be === Digest::MD5.hexdigest('404 page !')
end
end
describe '#rss_url' do
it 'returns nil if the url is not found' do
stub_request(:get, web_site.url).to_return(body: 'No RSS link in this body !')
web_site.rss_url.should be_nil
expect(web_site.rss_url).to be_nil
end
it "returns 'http://lamp-wp/wordpress-3.5/?feed=rss2'" do
stub_request_to_fixture(url: web_site.url, fixture: fixtures_dir + '/rss_url/wordpress-3.5.htm')
web_site.rss_url.should === 'http://lamp-wp/wordpress-3.5/?feed=rss2'
expect(web_site.rss_url).to be === 'http://lamp-wp/wordpress-3.5/?feed=rss2'
end
end
@@ -156,7 +156,7 @@ describe 'WebSite' do
after do
stub_request_to_fixture(url: log_url, fixture: fixtures_dir + "/has_log/#{@file}")
WebSite.has_log?(log_url, pattern).should == @expected
expect(WebSite.has_log?(log_url, pattern)).to eq @expected
end
context 'when the pattern does not match' do

View File

@@ -37,7 +37,7 @@ describe WpTarget do
it 'returns the login url of the target' do
stub_request(:get, login_url).to_return(status: 200, body: '')
wp_target.login_url.should === login_url
expect(wp_target.login_url).to be === login_url
end
it 'returns the redirection url if there is one (ie: for https)' do
@@ -46,7 +46,7 @@ describe WpTarget do
stub_request(:get, login_url).to_return(status: 302, headers: { location: https_login_url })
stub_request(:get, https_login_url).to_return(status: 200)
wp_target.login_url.should === https_login_url
expect(wp_target.login_url).to be === https_login_url
end
end
@@ -57,7 +57,7 @@ describe WpTarget do
to_return(status: 200, body: '', headers: { 'X-Pingback' => wp_target.uri.merge('xmlrpc.php')})
# Preventing redirection check from login_url()
wp_target.stub(redirection: nil)
allow(wp_target).to receive_messages(redirection: nil)
[wp_target.login_url, wp_target.xml_rpc_url].each do |url|
stub_request(:get, url).to_return(status: 404, body: '')
@@ -67,25 +67,25 @@ describe WpTarget do
it 'returns true if there is a /wp-content/ detected in the index page source' do
stub_request_to_fixture(url: wp_target.url, fixture: fixtures_dir + '/wp_content_dir/wordpress-3.4.1.htm')
wp_target.should be_wordpress
expect(wp_target).to be_wordpress
end
it 'returns true if the xmlrpc is found' do
stub_request(:get, wp_target.xml_rpc_url).
to_return(status: 200, body: File.new(fixtures_dir + '/xmlrpc.php'))
wp_target.should be_wordpress
expect(wp_target).to be_wordpress
end
it 'returns true if the wp-login is found and is a valid wordpress one' do
stub_request(:get, wp_target.login_url).
to_return(status: 200, body: File.new(fixtures_dir + '/wp-login.php'))
wp_target.should be_wordpress
expect(wp_target).to be_wordpress
end
it 'returns false if both files are not found (404)' do
wp_target.should_not be_wordpress
expect(wp_target).not_to be_wordpress
end
context 'when the url contains "wordpress" and is a 404' do
@@ -94,7 +94,7 @@ describe WpTarget do
it 'returns false' do
stub_request(:get, wp_target.login_url).to_return(status: 404, body: 'The requested URL /wordpress-3.5. was not found on this server.')
wp_target.should_not be_wordpress
expect(wp_target).not_to be_wordpress
end
end
@@ -110,17 +110,17 @@ describe WpTarget do
describe '#wordpress_hosted?' do
it 'returns true if target url is a wordpress.com subdomain' do
target = WpTarget.new('http://test.wordpress.com/')
target.wordpress_hosted?.should be_true
expect(target.wordpress_hosted?).to be_truthy
end
it 'returns true if target url is a wordpress.com subdomain and has querystring' do
target = WpTarget.new('http://test.wordpress.com/path/file.php?a=b')
target.wordpress_hosted?.should be_true
expect(target.wordpress_hosted?).to be_truthy
end
it 'returns false if target url is not a wordpress.com subdomain' do
target = WpTarget.new('http://test.example.com/')
target.wordpress_hosted?.should be_false
expect(target.wordpress_hosted?).to be_falsey
end
end
@@ -128,7 +128,7 @@ describe WpTarget do
it 'returns nil if no redirection detected' do
stub_request(:get, wp_target.url).to_return(status: 200, body: '')
wp_target.redirection.should be_nil
expect(wp_target.redirection).to be_nil
end
[301, 302].each do |status_code|
@@ -140,7 +140,7 @@ describe WpTarget do
stub_request(:get, new_location).to_return(status: 200)
wp_target.redirection.should === 'http://new-location.com'
expect(wp_target.redirection).to be === 'http://new-location.com'
end
end
@@ -153,15 +153,15 @@ describe WpTarget do
stub_request(:get, first_redirection).to_return(status: 302, headers: { location: last_redirection })
stub_request(:get, last_redirection).to_return(status: 200)
wp_target.redirection.should === last_redirection
expect(wp_target.redirection).to be === last_redirection
end
end
end
describe '#debug_log_url' do
it "returns 'http://example.localhost/wp-content/debug.log" do
wp_target.stub(wp_content_dir: 'wp-content')
wp_target.debug_log_url.should === 'http://example.localhost/wp-content/debug.log'
allow(wp_target).to receive_messages(wp_content_dir: 'wp-content')
expect(wp_target.debug_log_url).to be === 'http://example.localhost/wp-content/debug.log'
end
end
@@ -169,9 +169,9 @@ describe WpTarget do
let(:fixtures_dir) { SPEC_FIXTURES_WPSCAN_WP_TARGET_DIR + '/debug_log' }
after :each do
wp_target.stub(wp_content_dir: 'wp-content')
allow(wp_target).to receive_messages(wp_content_dir: 'wp-content')
stub_request_to_fixture(url: wp_target.debug_log_url(), fixture: @fixture)
wp_target.has_debug_log?.should === @expected
expect(wp_target.has_debug_log?).to be === @expected
end
it 'returns false' do
@@ -192,24 +192,24 @@ describe WpTarget do
describe '#search_replace_db_2_url' do
it 'returns the correct url' do
wp_target.search_replace_db_2_url.should == 'http://example.localhost/searchreplacedb2.php'
expect(wp_target.search_replace_db_2_url).to eq 'http://example.localhost/searchreplacedb2.php'
end
end
describe '#search_replace_db_2_exists?' do
it 'returns true' do
stub_request(:any, wp_target.search_replace_db_2_url).to_return(status: 200, body: 'asdf by interconnect asdf')
wp_target.search_replace_db_2_exists?.should be_true
expect(wp_target.search_replace_db_2_exists?).to be_truthy
end
it 'returns false' do
stub_request(:any, wp_target.search_replace_db_2_url).to_return(status: 500)
wp_target.search_replace_db_2_exists?.should be_false
expect(wp_target.search_replace_db_2_exists?).to be_falsey
end
it 'returns false' do
stub_request(:any, wp_target.search_replace_db_2_url).to_return(status: 500, body: 'asdf by interconnect asdf')
wp_target.search_replace_db_2_exists?.should be_false
expect(wp_target.search_replace_db_2_exists?).to be_falsey
end
end

View File

@@ -11,7 +11,7 @@ describe 'WpscanOptions' do
describe '#initialize' do
it 'should set all options to nil' do
WpscanOptions::ACCESSOR_OPTIONS.each do |option|
@wpscan_options.send(option).should === nil
expect(@wpscan_options.send(option)).to be === nil
end
end
end
@@ -24,27 +24,27 @@ describe 'WpscanOptions' do
it 'should add the http protocol if not present' do
@wpscan_options.url = 'example.com'
@wpscan_options.url.should === 'http://example.com'
expect(@wpscan_options.url).to be === 'http://example.com'
end
it "should not add the http protocol if it's already present" do
url = 'http://example.com'
@wpscan_options.url = url
@wpscan_options.url.should === url
expect(@wpscan_options.url).to be === url
end
end
describe '#threads=' do
it 'should convert an integer in a string into an integr' do
@wpscan_options.threads = '10'
@wpscan_options.threads.should be_an Integer
@wpscan_options.threads.should === 10
expect(@wpscan_options.threads).to be_an Integer
expect(@wpscan_options.threads).to be === 10
end
it 'should set to correct number of threads' do
@wpscan_options.threads = 15
@wpscan_options.threads.should be_an Integer
@wpscan_options.threads.should === 15
expect(@wpscan_options.threads).to be_an Integer
expect(@wpscan_options.threads).to be === 15
end
end
@@ -57,7 +57,7 @@ describe 'WpscanOptions' do
wordlist_file = "#{SPEC_FIXTURES_WPSCAN_WPSCAN_OPTIONS_DIR}/wordlist.txt"
@wpscan_options.wordlist = wordlist_file
@wpscan_options.wordlist.should === wordlist_file
expect(@wpscan_options.wordlist).to be === wordlist_file
end
end
@@ -69,7 +69,7 @@ describe 'WpscanOptions' do
it 'should not raise an error' do
proxy = '127.0.0.1:3038'
@wpscan_options.proxy = proxy
@wpscan_options.proxy.should === proxy
expect(@wpscan_options.proxy).to be === proxy
end
end
@@ -81,7 +81,7 @@ describe 'WpscanOptions' do
it 'should not raise en error' do
proxy_auth = 'user:pass'
@wpscan_options.proxy_auth = proxy_auth
@wpscan_options.proxy_auth.should === proxy_auth
expect(@wpscan_options.proxy_auth).to be === proxy_auth
end
end
@@ -97,7 +97,7 @@ describe 'WpscanOptions' do
@wpscan_options.enumerate_only_vulnerable_plugins = false
@wpscan_options.enumerate_plugins = true
@wpscan_options.enumerate_plugins.should be_true
expect(@wpscan_options.enumerate_plugins).to be_truthy
end
end
@@ -113,7 +113,7 @@ describe 'WpscanOptions' do
@wpscan_options.enumerate_only_vulnerable_themes = false
@wpscan_options.enumerate_themes = true
@wpscan_options.enumerate_themes.should be_true
expect(@wpscan_options.enumerate_themes).to be_truthy
end
end
@@ -129,7 +129,7 @@ describe 'WpscanOptions' do
@wpscan_options.enumerate_plugins = false
@wpscan_options.enumerate_only_vulnerable_plugins = true
@wpscan_options.enumerate_only_vulnerable_plugins.should be_true
expect(@wpscan_options.enumerate_only_vulnerable_plugins).to be_truthy
end
end
@@ -145,7 +145,7 @@ describe 'WpscanOptions' do
@wpscan_options.enumerate_themes = false
@wpscan_options.enumerate_only_vulnerable_themes = true
@wpscan_options.enumerate_only_vulnerable_themes.should be_true
expect(@wpscan_options.enumerate_only_vulnerable_themes).to be_truthy
end
end
@@ -161,7 +161,7 @@ describe 'WpscanOptions' do
@wpscan_options.enumerate_themes = false
@wpscan_options.enumerate_all_themes = true
@wpscan_options.enumerate_all_themes.should be_true
expect(@wpscan_options.enumerate_all_themes).to be_truthy
end
end
@@ -177,7 +177,7 @@ describe 'WpscanOptions' do
@wpscan_options.enumerate_plugins = false
@wpscan_options.enumerate_all_plugins = true
@wpscan_options.enumerate_all_plugins.should be_true
expect(@wpscan_options.enumerate_all_plugins).to be_truthy
end
end
@@ -193,39 +193,39 @@ describe 'WpscanOptions' do
context 'valid format' do
it "should add the 'Basic' word and do the encode64. See RFC 2617" do
@wpscan_options.basic_auth = 'Aladdin:open sesame'
@wpscan_options.basic_auth.should == 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='
expect(@wpscan_options.basic_auth).to eq 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='
end
end
end
describe '#has_options?' do
it 'should return false' do
@wpscan_options.has_options?.should be_false
expect(@wpscan_options.has_options?).to be_falsey
end
it 'should return true' do
@wpscan_options.verbose = false
@wpscan_options.has_options?.should be_true
expect(@wpscan_options.has_options?).to be_truthy
end
end
describe '#to_h' do
it 'should return an empty hash' do
@wpscan_options.to_h.should be_a Hash
@wpscan_options.to_h.should be_empty
expect(@wpscan_options.to_h).to be_a Hash
expect(@wpscan_options.to_h).to be_empty
end
it 'should return a hash with :verbose = true' do
expected = {verbose: true}
@wpscan_options.verbose = true
@wpscan_options.to_h.should === expected
expect(@wpscan_options.to_h).to be === expected
end
end
describe '#clean_option' do
after :each do
WpscanOptions.clean_option(@option).should === @expected
expect(WpscanOptions.clean_option(@option)).to be === @expected
end
it "should return 'url'" do
@@ -246,7 +246,7 @@ describe 'WpscanOptions' do
describe '#option_to_instance_variable_setter' do
after :each do
WpscanOptions.option_to_instance_variable_setter(@argument).should === @expected
expect(WpscanOptions.option_to_instance_variable_setter(@argument)).to be === @expected
end
it 'should return :url=' do
@@ -277,12 +277,12 @@ describe 'WpscanOptions' do
describe '#is_long_option?' do
it 'should return true' do
WpscanOptions.is_long_option?('--url').should be_true
expect(WpscanOptions.is_long_option?('--url')).to be_truthy
end
it 'should return false' do
WpscanOptions.is_long_option?('hello').should be_false
WpscanOptions.is_long_option?('--enumerate').should be_false
expect(WpscanOptions.is_long_option?('hello')).to be_falsey
expect(WpscanOptions.is_long_option?('--enumerate')).to be_falsey
end
end
@@ -291,7 +291,7 @@ describe 'WpscanOptions' do
if @argument
wpscan_options = WpscanOptions.new
wpscan_options.enumerate_options_from_string(@argument)
wpscan_options.to_h.should === @expected_hash
expect(wpscan_options.to_h).to be === @expected_hash
end
end
@@ -341,20 +341,20 @@ describe 'WpscanOptions' do
it 'should set @url to example.com' do
@wpscan_options.set_option_from_cli('--url', 'example.com')
@wpscan_options.url.should === 'http://example.com'
expect(@wpscan_options.url).to be === 'http://example.com'
end
it 'should set @enumerate_plugins to true' do
@wpscan_options.set_option_from_cli('--enumerate', 'p')
@wpscan_options.enumerate_plugins.should be_true
@wpscan_options.enumerate_only_vulnerable_plugins.should be_nil
expect(@wpscan_options.enumerate_plugins).to be_truthy
expect(@wpscan_options.enumerate_only_vulnerable_plugins).to be_nil
end
it 'should set @enumerate_only_vulnerable_plugins, @enumerate_timthumbs and @enumerate_usernames to true if no argument is given' do
@wpscan_options.set_option_from_cli('--enumerate', '')
@wpscan_options.enumerate_only_vulnerable_plugins.should be_true
@wpscan_options.enumerate_timthumbs.should be_true
@wpscan_options.enumerate_usernames.should be_true
expect(@wpscan_options.enumerate_only_vulnerable_plugins).to be_truthy
expect(@wpscan_options.enumerate_timthumbs).to be_truthy
expect(@wpscan_options.enumerate_usernames).to be_truthy
end
end
@@ -362,7 +362,7 @@ describe 'WpscanOptions' do
after :each do
set_argv(@argv)
wpscan_options = WpscanOptions.load_from_arguments
wpscan_options.to_h.should === @expected_hash
expect(wpscan_options.to_h).to be === @expected_hash
end
it 'should return {}' do

View File

@@ -11,37 +11,37 @@ describe 'StatsPlugin' do
describe '#vuln_plugin_count' do
it 'returns the correct number' do
stats.vuln_plugin_count(plugins_vulns).should == 2
expect(stats.vuln_plugin_count(plugins_vulns)).to eq 2
end
end
describe '#vuln_theme_count' do
it 'returns the correct number' do
stats.vuln_theme_count(themes_vulns).should == 2
expect(stats.vuln_theme_count(themes_vulns)).to eq 2
end
end
describe '#plugin_vulns_count' do
it 'returns the correct number' do
stats.plugin_vulns_count(plugins_vulns).should == 3
expect(stats.plugin_vulns_count(plugins_vulns)).to eq 3
end
end
describe '#theme_vulns_count' do
it 'returns the correct number' do
stats.theme_vulns_count(themes_vulns).should == 3
expect(stats.theme_vulns_count(themes_vulns)).to eq 3
end
end
describe '#total_plugins' do
it 'returns the correct numer' do
stats.total_plugins(plugins_file).should == 3
expect(stats.total_plugins(plugins_file)).to eq 3
end
end
describe '#total_themes' do
it 'returns the correct numer' do
stats.total_themes(themes_file).should == 3
expect(stats.total_themes(themes_file)).to eq 3
end
end
end