swamp 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -14
- data/bin/swamp +7 -3
- data/features/specifications/scope_changing.feature +34 -0
- data/features/specifications/user_scans_buttons_in_a_page.feature +3 -3
- data/features/specifications/user_scans_fields_in_a_page.feature +3 -3
- data/features/specifications/user_scans_input_buttons_in_a_page.feature +2 -2
- data/features/specifications/user_scans_links_in_a_page.feature +1 -1
- data/features/specifications/user_scans_select_box_elements_in_a_page.feature +3 -3
- data/features/step_definitions/swamp_steps.rb +19 -8
- data/features/support/setup.rb +9 -4
- data/lib/swamp.rb +2 -0
- data/lib/swamp/assertions.rb +7 -0
- data/lib/swamp/builder.rb +10 -6
- data/lib/swamp/interface.rb +8 -2
- data/lib/swamp/setup.rb +49 -0
- data/lib/swamp/version.rb +1 -1
- data/lib/swamp/wrapper.rb +5 -4
- data/spec/spec_helper.rb +1 -1
- data/spec/swamp/builder_spec.rb +18 -8
- data/spec/swamp/buttons_spec.rb +37 -37
- data/spec/swamp/evaluator_spec.rb +10 -10
- data/spec/swamp/fields_spec.rb +36 -36
- data/spec/swamp/formatter_spec.rb +7 -7
- data/spec/swamp/input_buttons_spec.rb +24 -24
- data/spec/swamp/interface_spec.rb +31 -15
- data/spec/swamp/links_spec.rb +12 -12
- data/spec/swamp/select_boxes_spec.rb +30 -30
- data/spec/swamp/setup_spec.rb +41 -0
- data/spec/swamp/wrapper_spec.rb +28 -26
- metadata +32 -26
@@ -7,42 +7,42 @@ module Swamp
|
|
7
7
|
context "when the name has dashes" do
|
8
8
|
it "replaces the dashes with unsderscores" do
|
9
9
|
name = "user-name"
|
10
|
-
formatter.format(name).
|
10
|
+
expect(formatter.format(name)).to eq("user_name")
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
context "when the name has white spaces" do
|
15
15
|
it "replaces the white spaces with underscores" do
|
16
16
|
name = "user name"
|
17
|
-
formatter.format(name).
|
17
|
+
expect(formatter.format(name)).to eq("user_name")
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
context "when the name has underscore in the end" do
|
22
22
|
it "removes the underscores from the end" do
|
23
23
|
name = "user_name_"
|
24
|
-
formatter.format(name).
|
24
|
+
expect(formatter.format(name)).to eq("user_name")
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
context "when the name has uppercase characters" do
|
29
29
|
it "converts the characters to lowercase" do
|
30
30
|
name = "Sign up"
|
31
|
-
formatter.format(name).
|
31
|
+
expect(formatter.format(name)).to eq("sign_up")
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
context "when the name has parentheses" do
|
36
36
|
it "replace the parentheses with underscores" do
|
37
37
|
name = "user_name(title)"
|
38
|
-
formatter.format(name).
|
38
|
+
expect(formatter.format(name)).to eq("user_name_title")
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
context "when the name has brackets" do
|
43
43
|
it "replace the brackets with underscores" do
|
44
44
|
name = "user_name[title]"
|
45
|
-
formatter.format(name).
|
45
|
+
expect(formatter.format(name)).to eq("user_name_title")
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -51,7 +51,7 @@ module Swamp
|
|
51
51
|
context "when the class has white spaces" do
|
52
52
|
it "replaces the white spaces with dots" do
|
53
53
|
class_name = "button g-button g-button-submit"
|
54
|
-
formatter.format_class(class_name).
|
54
|
+
expect(formatter.format_class(class_name)).to eq("button.g-button.g-button-submit")
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -5,9 +5,9 @@ module Swamp
|
|
5
5
|
|
6
6
|
it "delegates to capybara the responsibility to get the submit elements" do
|
7
7
|
element = {'value' => "Log In", 'id' => "u_0_b"}
|
8
|
-
element.
|
9
|
-
input_buttons.page.
|
10
|
-
input_buttons.page.
|
8
|
+
allow(element).to receive(:visible?).and_return(true)
|
9
|
+
allow(input_buttons.page).to receive(:execute_script).and_return(nil)
|
10
|
+
expect(input_buttons.page).to receive(:all).with('input[type="submit"]').and_return([element])
|
11
11
|
input_buttons.get
|
12
12
|
end
|
13
13
|
|
@@ -16,25 +16,25 @@ module Swamp
|
|
16
16
|
let(:element) { {'value' => "Log In", 'id' => "u_0_b"} }
|
17
17
|
|
18
18
|
before(:each) do
|
19
|
-
element.
|
20
|
-
input_buttons.page.
|
19
|
+
allow(element).to receive(:visible?).and_return(true)
|
20
|
+
allow(input_buttons.page).to receive(:all).with('input[type="submit"]').and_return([element])
|
21
21
|
end
|
22
22
|
|
23
23
|
it "highlights the element" do
|
24
|
-
input_buttons.page.
|
24
|
+
expect(input_buttons.page).to receive(:execute_script).twice
|
25
25
|
input_buttons.get
|
26
26
|
end
|
27
27
|
|
28
28
|
it "returns the element in the array using the value as the name" do
|
29
|
-
input_buttons.page.
|
30
|
-
input_buttons.get.
|
31
|
-
input_buttons.get.first.name.
|
29
|
+
allow(input_buttons.page).to receive(:execute_script).and_return(nil)
|
30
|
+
expect(input_buttons.get.size).to eq(1)
|
31
|
+
expect(input_buttons.get.first.name).to eq("Log In")
|
32
32
|
end
|
33
33
|
|
34
34
|
it "returns the element in the array using the id as the selector" do
|
35
|
-
input_buttons.page.
|
36
|
-
input_buttons.get.
|
37
|
-
input_buttons.get.first.selector.
|
35
|
+
allow(input_buttons.page).to receive(:execute_script).and_return(nil)
|
36
|
+
expect(input_buttons.get.size).to eq(1)
|
37
|
+
expect(input_buttons.get.first.selector).to eq("#u_0_b")
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -42,25 +42,25 @@ module Swamp
|
|
42
42
|
let(:element) { {'value' => "Log In", 'class' => "btn without id"} }
|
43
43
|
|
44
44
|
before(:each) do
|
45
|
-
element.
|
46
|
-
input_buttons.page.
|
45
|
+
allow(element).to receive(:visible?).and_return(true)
|
46
|
+
allow(input_buttons.page).to receive(:all).with('input[type="submit"]').and_return([element])
|
47
47
|
end
|
48
48
|
|
49
49
|
it "highlights the element" do
|
50
|
-
input_buttons.page.
|
50
|
+
expect(input_buttons.page).to receive(:execute_script).twice
|
51
51
|
input_buttons.get
|
52
52
|
end
|
53
53
|
|
54
54
|
it "returns the element in the array using the value as the name" do
|
55
|
-
input_buttons.page.
|
56
|
-
input_buttons.get.
|
57
|
-
input_buttons.get.first.name.
|
55
|
+
allow(input_buttons.page).to receive(:execute_script).and_return(nil)
|
56
|
+
expect(input_buttons.get.size).to eq(1)
|
57
|
+
expect(input_buttons.get.first.name).to eq("Log In")
|
58
58
|
end
|
59
59
|
|
60
60
|
it "returns the element in the array using the class concatenated with the value as the selector" do
|
61
|
-
input_buttons.page.
|
62
|
-
input_buttons.get.
|
63
|
-
input_buttons.get.first.selector.
|
61
|
+
allow(input_buttons.page).to receive(:execute_script).and_return(nil)
|
62
|
+
expect(input_buttons.get.size).to eq(1)
|
63
|
+
expect(input_buttons.get.first.selector).to eq("input.btn.without.id[value='Log In']")
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -68,9 +68,9 @@ module Swamp
|
|
68
68
|
context "when the element is not visible" do
|
69
69
|
it "returns an empty array" do
|
70
70
|
element = {'value' => "Log In", 'id' => "u_0_b"}
|
71
|
-
element.
|
72
|
-
input_buttons.page.
|
73
|
-
input_buttons.get.
|
71
|
+
allow(element).to receive(:visible?).and_return(false)
|
72
|
+
allow(input_buttons.page).to receive(:all).with('input[type="submit"]').and_return([element])
|
73
|
+
expect(input_buttons.get).to eq([])
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -3,44 +3,60 @@ module Swamp
|
|
3
3
|
describe Interface do
|
4
4
|
let(:output) { output = double('output').as_null_object }
|
5
5
|
let(:wrapper) { wrapper = double('wrapper').as_null_object }
|
6
|
-
let(:
|
6
|
+
let(:setup) { setup = Swamp::Setup.new }
|
7
|
+
let(:interface) { interface = Swamp::Interface.new(output, wrapper, setup) }
|
7
8
|
|
8
9
|
describe "#run" do
|
9
10
|
it "prompts for the url" do
|
10
|
-
output.
|
11
|
+
expect(output).to receive(:puts).with("Enter the url for the page to be scanned:")
|
11
12
|
interface.run
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
16
|
+
describe "#setup_command" do
|
17
|
+
let(:command) { ":scope = source" }
|
18
|
+
it "delegates the responsibility to execute the command to the Setup class" do
|
19
|
+
expect(setup).to receive(:handle_command).with(command).and_return(["something"])
|
20
|
+
interface.setup_command(command)
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when it receives a valid command" do
|
24
|
+
it "sends a message to the output telling that the command was successful" do
|
25
|
+
expect(output).to receive(:puts).with("Option :scope set to source")
|
26
|
+
interface.setup_command(command)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
15
31
|
describe "#scan" do
|
16
32
|
it "warns the user that it is scanning" do
|
17
|
-
output.
|
33
|
+
expect(output).to receive(:puts).with("Scanning, please wait...")
|
18
34
|
interface.scan("http://www.fakepage.com")
|
19
35
|
end
|
20
36
|
|
21
37
|
it "delegates the responsibility to fire up the browser to the wrapper class" do
|
22
|
-
wrapper.
|
38
|
+
expect(wrapper).to receive(:explore)
|
23
39
|
interface.scan("http://www.fakepage.com")
|
24
40
|
end
|
25
41
|
|
26
42
|
it "delegates the page parsing to the wrapper class" do
|
27
|
-
wrapper.
|
43
|
+
expect(wrapper).to receive(:scan).and_return(["code_snippet"])
|
28
44
|
interface.scan("http://www.fakepage.com")
|
29
45
|
end
|
30
46
|
|
31
47
|
context "when it scans a valid url" do
|
32
48
|
context "when elements were found" do
|
33
49
|
it "sends the code snippets of the scanned page to the output" do
|
34
|
-
wrapper.
|
35
|
-
output.
|
50
|
+
allow(wrapper).to receive(:scan).and_return(["code_snippet"])
|
51
|
+
expect(output).to receive(:puts).with("code_snippet")
|
36
52
|
interface.scan("http://www.fakepage.com")
|
37
53
|
end
|
38
54
|
end
|
39
55
|
|
40
56
|
context "when no elements were found" do
|
41
57
|
it "sends a warning message to the output telling that no elements were found" do
|
42
|
-
wrapper.
|
43
|
-
output.
|
58
|
+
allow(wrapper).to receive(:scan).and_return([])
|
59
|
+
expect(output).to receive(:puts).with("No elements were detected")
|
44
60
|
interface.scan("http://www.fakepage.com")
|
45
61
|
end
|
46
62
|
end
|
@@ -48,7 +64,7 @@ module Swamp
|
|
48
64
|
|
49
65
|
context "when it scans an invalid url" do
|
50
66
|
it "sends a warning message to the output" do
|
51
|
-
output.
|
67
|
+
expect(output).to receive(:puts).with("Please enter a valid url!")
|
52
68
|
interface.scan("abc123")
|
53
69
|
end
|
54
70
|
end
|
@@ -56,17 +72,17 @@ module Swamp
|
|
56
72
|
context "when it receives an enter keystroke" do
|
57
73
|
context "when no page was scanned yet" do
|
58
74
|
it "sends a warning message to the output" do
|
59
|
-
wrapper.
|
60
|
-
output.
|
75
|
+
allow(wrapper).to receive(:page_visited).and_return(false)
|
76
|
+
expect(output).to receive(:puts).with("Please enter a valid url!")
|
61
77
|
interface.scan("\n")
|
62
78
|
end
|
63
79
|
end
|
64
80
|
|
65
81
|
context "when a page was already scanned" do
|
66
82
|
it "scans the current page and sends the code snippets to the output" do
|
67
|
-
wrapper.
|
68
|
-
wrapper.
|
69
|
-
output.
|
83
|
+
allow(wrapper).to receive(:page_visited).and_return(true)
|
84
|
+
allow(wrapper).to receive(:scan).and_return(["code_snippet"])
|
85
|
+
expect(output).to receive(:puts).with("code_snippet")
|
70
86
|
interface.scan("\n")
|
71
87
|
end
|
72
88
|
end
|
data/spec/swamp/links_spec.rb
CHANGED
@@ -5,9 +5,9 @@ module Swamp
|
|
5
5
|
|
6
6
|
it "delegates to capybara the responsibility to get the links" do
|
7
7
|
element = {'id' => "forgot-password", 'href' => "https://somewhere.com"}
|
8
|
-
element.
|
9
|
-
links.page.
|
10
|
-
links.page.
|
8
|
+
allow(element).to receive(:visible?).and_return(true)
|
9
|
+
allow(links.page).to receive(:execute_script).and_return(nil)
|
10
|
+
expect(links.page).to receive(:all).with('a[href][id]').and_return([element])
|
11
11
|
links.get
|
12
12
|
end
|
13
13
|
|
@@ -16,25 +16,25 @@ module Swamp
|
|
16
16
|
let(:element) { {'id' => "forgot-password", 'href' => "https://somewhere.com"} }
|
17
17
|
|
18
18
|
before(:each) do
|
19
|
-
element.
|
20
|
-
links.page.
|
19
|
+
allow(element).to receive(:visible?).and_return(true)
|
20
|
+
allow(links.page).to receive(:all).with('a[href][id]').and_return([element])
|
21
21
|
end
|
22
22
|
|
23
23
|
it "highlights the element" do
|
24
|
-
links.page.
|
24
|
+
expect(links.page).to receive(:execute_script).and_return(nil)
|
25
25
|
links.get
|
26
26
|
end
|
27
27
|
|
28
28
|
it "returns the element in the array using the id as the name" do
|
29
|
-
links.page.
|
30
|
-
links.get.
|
31
|
-
links.get.first.name.
|
29
|
+
allow(links.page).to receive(:execute_script).and_return(nil)
|
30
|
+
expect(links.get.size).to eq(1)
|
31
|
+
expect(links.get.first.name).to eq("forgot-password")
|
32
32
|
end
|
33
33
|
|
34
34
|
it "returns the element in the array using the id as the selector" do
|
35
|
-
links.page.
|
36
|
-
links.get.
|
37
|
-
links.get.first.selector.
|
35
|
+
allow(links.page).to receive(:execute_script).and_return(nil)
|
36
|
+
expect(links.get.size).to eq(1)
|
37
|
+
expect(links.get.first.selector).to eq("forgot-password")
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -5,9 +5,9 @@ module Swamp
|
|
5
5
|
|
6
6
|
it "delegates to capybara the responsibility to get the select box elements" do
|
7
7
|
element = {'id' => "month", 'name' => "birthday_month"}
|
8
|
-
element.
|
9
|
-
select_boxes.page.
|
10
|
-
select_boxes.page.
|
8
|
+
allow(element).to receive(:visible?).and_return(true)
|
9
|
+
allow(select_boxes.page).to receive(:execute_script).and_return(nil)
|
10
|
+
expect(select_boxes.page).to receive(:all).with('select').and_return([element])
|
11
11
|
select_boxes.get
|
12
12
|
end
|
13
13
|
|
@@ -16,25 +16,25 @@ module Swamp
|
|
16
16
|
let(:element) { {'id' => "month", 'name' => "birthday_month"} }
|
17
17
|
|
18
18
|
before(:each) do
|
19
|
-
element.
|
20
|
-
select_boxes.page.
|
19
|
+
allow(element).to receive(:visible?).and_return(true)
|
20
|
+
allow(select_boxes.page).to receive(:all).with('select').and_return([element])
|
21
21
|
end
|
22
22
|
|
23
23
|
it "highlights the element" do
|
24
|
-
select_boxes.page.
|
24
|
+
expect(select_boxes.page).to receive(:execute_script).twice
|
25
25
|
select_boxes.get
|
26
26
|
end
|
27
27
|
|
28
28
|
it "returns the element in the array using the id as the name" do
|
29
|
-
select_boxes.page.
|
30
|
-
select_boxes.get.
|
31
|
-
select_boxes.get.first.name.
|
29
|
+
allow(select_boxes.page).to receive(:execute_script).and_return(nil)
|
30
|
+
expect(select_boxes.get.size).to eq(1)
|
31
|
+
expect(select_boxes.get.first.name).to eq("month")
|
32
32
|
end
|
33
33
|
|
34
34
|
it "returns the element in the array using the id as the selector" do
|
35
|
-
select_boxes.page.
|
36
|
-
select_boxes.get.
|
37
|
-
select_boxes.get.first.selector.
|
35
|
+
allow(select_boxes.page).to receive(:execute_script).and_return(nil)
|
36
|
+
expect(select_boxes.get.size).to eq(1)
|
37
|
+
expect(select_boxes.get.first.selector).to eq("month")
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -42,25 +42,25 @@ module Swamp
|
|
42
42
|
let(:element) { {'name' => "birthday_month"} }
|
43
43
|
|
44
44
|
before(:each) do
|
45
|
-
element.
|
46
|
-
select_boxes.page.
|
45
|
+
allow(element).to receive(:visible?).and_return(true)
|
46
|
+
allow(select_boxes.page).to receive(:all).with('select').and_return([element])
|
47
47
|
end
|
48
48
|
|
49
49
|
it "highlights the element" do
|
50
|
-
select_boxes.page.
|
50
|
+
expect(select_boxes.page).to receive(:execute_script).twice
|
51
51
|
select_boxes.get
|
52
52
|
end
|
53
53
|
|
54
54
|
it "returns the element in the array using the name as the name" do
|
55
|
-
select_boxes.page.
|
56
|
-
select_boxes.get.
|
57
|
-
select_boxes.get.first.name.
|
55
|
+
allow(select_boxes.page).to receive(:execute_script).and_return(nil)
|
56
|
+
expect(select_boxes.get.size).to eq(1)
|
57
|
+
expect(select_boxes.get.first.name).to eq("birthday_month")
|
58
58
|
end
|
59
59
|
|
60
60
|
it "returns the element in the array using the name as the selector" do
|
61
|
-
select_boxes.page.
|
62
|
-
select_boxes.get.
|
63
|
-
select_boxes.get.first.selector.
|
61
|
+
allow(select_boxes.page).to receive(:execute_script).and_return(nil)
|
62
|
+
expect(select_boxes.get.size).to eq(1)
|
63
|
+
expect(select_boxes.get.first.selector).to eq("birthday_month")
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -68,25 +68,25 @@ module Swamp
|
|
68
68
|
let(:element) { {'class' => "provider-select"} }
|
69
69
|
|
70
70
|
before(:each) do
|
71
|
-
element.
|
72
|
-
select_boxes.page.
|
71
|
+
allow(element).to receive(:visible?).and_return(true)
|
72
|
+
allow(select_boxes.page).to receive(:all).with('select').and_return([element])
|
73
73
|
end
|
74
74
|
|
75
75
|
it "highlights the element" do
|
76
|
-
select_boxes.page.
|
76
|
+
expect(select_boxes.page).to receive(:execute_script).twice
|
77
77
|
select_boxes.get
|
78
78
|
end
|
79
79
|
|
80
80
|
it "returns the element in the array using the class as the name" do
|
81
|
-
select_boxes.page.
|
82
|
-
select_boxes.get.
|
83
|
-
select_boxes.get.first.name.
|
81
|
+
allow(select_boxes.page).to receive(:execute_script).and_return(nil)
|
82
|
+
expect(select_boxes.get.size).to eq(1)
|
83
|
+
expect(select_boxes.get.first.name).to eq("provider-select")
|
84
84
|
end
|
85
85
|
|
86
86
|
it "returns the element in the array using the class as the selector" do
|
87
|
-
select_boxes.page.
|
88
|
-
select_boxes.get.
|
89
|
-
select_boxes.get.first.selector.
|
87
|
+
allow(select_boxes.page).to receive(:execute_script).and_return(nil)
|
88
|
+
expect(select_boxes.get.size).to eq(1)
|
89
|
+
expect(select_boxes.get.first.selector).to eq("provider-select")
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Swamp
|
3
|
+
describe Setup do
|
4
|
+
let(:setup) { Swamp::Setup.new }
|
5
|
+
|
6
|
+
it "should set the default options" do
|
7
|
+
expect(setup.scope).to eq("page")
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#handle_command" do
|
11
|
+
context "when the command is valid" do
|
12
|
+
context "when the scope changes" do
|
13
|
+
it "should set the option :scope to source" do
|
14
|
+
setup.handle_command(":scope = source")
|
15
|
+
expect(setup.scope).to eq("source")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return a message confirming the scope was set to source" do
|
19
|
+
expect(setup.handle_command(":scope = source")).to eq(["Option :scope set to source"])
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should set the option :scope to page" do
|
23
|
+
setup.handle_command(":scope = page")
|
24
|
+
expect(setup.scope).to eq("page")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return a message confirming the scope was set to page" do
|
28
|
+
expect(setup.handle_command(":scope = page")).to eq(["Option :scope set to page"])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when the command is invalid" do
|
34
|
+
it "should return a message warning that the command is invalid" do
|
35
|
+
expect(setup.handle_command(":scope = ")).to eq(["Invalid command"])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|