Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wpscanteam
GitHub Repository: wpscanteam/wpscan
Path: blob/master/spec/app/views_spec.rb
485 views
1
# frozen_string_literal: true
2
3
describe 'App::Views' do
4
let(:target_url) { 'http://ex.lo/' }
5
let(:target) { WPScan::Target.new(target_url) }
6
let(:fixtures) { SPECS.join('output') }
7
8
# CliNoColour is used to test the CLI output to avoid the painful colours
9
# in the expected output.
10
%i[JSON CliNoColour].each do |formatter|
11
context "when #{formatter}" do
12
it_behaves_like 'App::Views::VulnApi'
13
it_behaves_like 'App::Views::WpVersion'
14
it_behaves_like 'App::Views::MainTheme'
15
it_behaves_like 'App::Views::Enumeration'
16
17
let(:parsed_options) { { url: target_url, format: formatter.to_s.underscore.dasherize } }
18
19
before do
20
WPScan::ParsedCli.options = parsed_options
21
# Resets the formatter to ensure the correct one is loaded
22
controller.class.class_variable_set(:@@formatter, nil)
23
end
24
25
after do
26
view_filename = defined?(expected_view) ? expected_view : view
27
view_filename = "#{view_filename}.#{formatter.to_s.underscore.downcase}"
28
controller_dir = controller.class.to_s.demodulize.underscore.downcase
29
expected_output = File.read(fixtures.join(controller_dir, view_filename))
30
31
expect($stdout).to receive(:puts).with(expected_output)
32
33
controller.output(view, @tpl_vars)
34
controller.formatter.beautify # Mandatory to be able to test formatter such as JSON
35
end
36
end
37
end
38
end
39
40