golden_silk 0.0.1 → 0.0.2.pumpkin

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afe64d6d1edef3d19df952635be97feb5cd58736
4
- data.tar.gz: 444c935fff7813885d31716ebbf66c678d5afe92
3
+ metadata.gz: 837c3ae481ed052bf24042cdcf26a3bdfd77663e
4
+ data.tar.gz: b713946e8d511a9dd69c260d98f90b54e6f05515
5
5
  SHA512:
6
- metadata.gz: cd4b9e32018ed2a2527ba328e3ab564aa75ce6e9719d941811ec43eefcd39486a0f22255901ac4913b02dc3818b01473d0908a736edb77c91e9825ba840139dc
7
- data.tar.gz: afebff612ab3eb227e5538357f652abfdf7378e9073f194c8a119d01e3b5a010fefa2e6a2035b0a4dbf468525bc5d7d9173b5fa0d839e4ac4f1ff022e0c1e17e
6
+ metadata.gz: 208a5e692b053e186b3fbb2a6449a61d654cc2eb7c47a6152a39a1b7f9093ffa3d2e922caf5eec89c09bfbec6029e16c4728c058c5797ca29ebfae70a2d72786
7
+ data.tar.gz: fdda1169f15bf9cdc75ae3daafc74274cc2fc5c4b0148de1aa7b702273e3f9953c757a65026d759148b0e5130b2bd16e83f8f78709ba8b3df3f23f281231d460
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ golden_silk
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.5
data/bin/golden_silk ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'golden_silk'
4
+
5
+ # TODO: take URL as an argument
6
+ GoldenSilk::Spinner.new('http://0.0.0.0:9001/avatar_builder').run
data/golden_silk.gemspec CHANGED
@@ -17,6 +17,10 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
+ spec.add_dependency "capybara", "~> 2.4.4"
21
+ spec.add_dependency "capybara-webkit", "~> 1.4.1"
22
+ spec.add_dependency "diffy"
23
+
20
24
  spec.add_development_dependency "bundler", "~> 1.6"
21
- spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rake", "~> 10.4.2"
22
26
  end
data/lib/golden_silk.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "golden_silk/version"
2
-
3
- module GoldenSilk
4
- # Your code goes here...
5
- end
2
+ require "golden_silk/spinner"
3
+ require "golden_silk/result/diff"
4
+ require "golden_silk/result/no_effect"
5
+ require "golden_silk/step/click"
6
+ require "golden_silk/step/visit"
@@ -0,0 +1,27 @@
1
+ module GoldenSilk
2
+ module Result
3
+ class Diff
4
+ def initialize(options = {})
5
+ @steps = options[:steps]
6
+ @diff = options[:diff]
7
+ end
8
+
9
+ def to_s
10
+ s = "Steps:\n"
11
+ s << @steps.join("\n") + "\n"
12
+ s << "Diff:\n"
13
+ in_diff = true
14
+ @diff.split("\n").each do |line|
15
+ if line.match(/^ /) && in_diff
16
+ in_diff = false
17
+ s << " ...\n"
18
+ elsif !line.match(/^ /)
19
+ in_diff = true
20
+ s << " " + line + "\n"
21
+ end
22
+ end
23
+ s
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ module GoldenSilk
2
+ module Result
3
+ class NoEffect
4
+ def initialize(options = {})
5
+ @steps = options[:steps]
6
+ end
7
+
8
+ def to_s
9
+ s = "Steps:\n"
10
+ s << @steps.join("\n")
11
+ s
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,95 @@
1
+ require 'capybara/dsl'
2
+ require 'capybara/webkit'
3
+ require 'diffy'
4
+
5
+ module GoldenSilk
6
+ class Spinner
7
+ include Capybara::DSL
8
+
9
+ # TODO: configurable depth
10
+ MAX_DEPTH = 3
11
+
12
+ # TODO: configurable capybara driver
13
+ Capybara.default_driver = :webkit
14
+
15
+ Diffy::Diff.default_format = :text
16
+
17
+ def initialize(root_url)
18
+ @root_url = root_url
19
+ # TODO: configurable click selector, take into account disabled states
20
+ @click_selector = 'button, .store-accessory'
21
+ @results = []
22
+ @queue = []
23
+ end
24
+
25
+ def run
26
+ # TODO: get host from root_url
27
+ page.driver.allow_url("0.0.0.0")
28
+ page.driver.block_unknown_urls
29
+
30
+ visit @root_url
31
+ # TODO: configurable wait time
32
+ sleep 2
33
+ all(@click_selector).each { |node|
34
+ @queue << [
35
+ Step::Visit.new(url: @root_url, on: self),
36
+ Step::Click.new(xpath: node.path, text: node.text, on: self)
37
+ ]
38
+ }
39
+ stuff(@queue, @results)
40
+
41
+ @results.each do |result|
42
+ # TODO: quiet mode (or quiet by default and verbose mode)
43
+ puts "==============="
44
+ puts result
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ # TODO: better name, don't take queue/results as arguments
51
+ def stuff(queue, results)
52
+ if queue.empty?
53
+ puts "Queue is empty, we're done!"
54
+ return
55
+ end
56
+
57
+ current_action_set = queue.shift
58
+ depth = current_action_set.length
59
+
60
+ last_action = current_action_set.pop
61
+
62
+ current_action_set.each { |a| a.execute }
63
+ sleep 2
64
+ before_snapshot = html
65
+ last_action.execute
66
+ sleep 2
67
+ after_snapshot = html
68
+ diff = Diffy::Diff.new(before_snapshot, after_snapshot).to_s
69
+
70
+ if diff.empty?
71
+ puts "No change, adding to results but not queue."
72
+ results << Result::NoEffect.new(steps: current_action_set + [last_action])
73
+ else
74
+ puts "Change, adding to results."
75
+ results << Result::Diff.new(diff: diff, steps: current_action_set + [last_action])
76
+
77
+ if depth == MAX_DEPTH
78
+ puts "Hit max depth."
79
+ else
80
+ puts "Looking for more steps to take."
81
+
82
+ all(@click_selector).map { |node|
83
+ queue << current_action_set + [
84
+ last_action,
85
+ Step::Click.new(xpath: node.path, text: node.text, on: self)
86
+ ]
87
+ }
88
+ end
89
+ end
90
+
91
+ puts "Recursing. Queue length: #{queue.length}, Results length: #{results.length}"
92
+ stuff(queue, results)
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,20 @@
1
+ module GoldenSilk
2
+ module Step
3
+ class Click
4
+ def initialize(options = {})
5
+ @xpath = options[:xpath]
6
+ @text = options[:text]
7
+ @object = options[:on]
8
+ end
9
+
10
+ def execute
11
+ puts "Following instructions to click #{@text}"
12
+ @object.find(:xpath, @xpath).click
13
+ end
14
+
15
+ def to_s
16
+ "Click #{@text}"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ module GoldenSilk
2
+ module Step
3
+ class Visit
4
+ def initialize(options = {})
5
+ @url = options[:url]
6
+ @object = options[:on]
7
+ end
8
+
9
+ def execute
10
+ puts "Visiting #{@url}"
11
+ @object.visit @url
12
+ end
13
+
14
+ def to_s
15
+ "visit '#{@url}'"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module GoldenSilk
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2.pumpkin"
3
3
  end
metadata CHANGED
@@ -1,57 +1,108 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: golden_silk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2.pumpkin
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carol (Nichols || Goulding)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-14 00:00:00.000000000 Z
11
+ date: 2015-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capybara
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.4.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.4.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: capybara-webkit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.4.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.4.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: diffy
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
13
55
  - !ruby/object:Gem::Dependency
14
56
  name: bundler
15
57
  requirement: !ruby/object:Gem::Requirement
16
58
  requirements:
17
- - - ~>
59
+ - - "~>"
18
60
  - !ruby/object:Gem::Version
19
61
  version: '1.6'
20
62
  type: :development
21
63
  prerelease: false
22
64
  version_requirements: !ruby/object:Gem::Requirement
23
65
  requirements:
24
- - - ~>
66
+ - - "~>"
25
67
  - !ruby/object:Gem::Version
26
68
  version: '1.6'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: rake
29
71
  requirement: !ruby/object:Gem::Requirement
30
72
  requirements:
31
- - - '>='
73
+ - - "~>"
32
74
  - !ruby/object:Gem::Version
33
- version: '0'
75
+ version: 10.4.2
34
76
  type: :development
35
77
  prerelease: false
36
78
  version_requirements: !ruby/object:Gem::Requirement
37
79
  requirements:
38
- - - '>='
80
+ - - "~>"
39
81
  - !ruby/object:Gem::Version
40
- version: '0'
82
+ version: 10.4.2
41
83
  description:
42
84
  email:
43
85
  - carol.nichols@gmail.com
44
- executables: []
86
+ executables:
87
+ - golden_silk
45
88
  extensions: []
46
89
  extra_rdoc_files: []
47
90
  files:
48
- - .gitignore
91
+ - ".gitignore"
92
+ - ".ruby-gemset"
93
+ - ".ruby-version"
49
94
  - Gemfile
50
95
  - LICENSE.txt
51
96
  - README.md
52
97
  - Rakefile
98
+ - bin/golden_silk
53
99
  - golden_silk.gemspec
54
100
  - lib/golden_silk.rb
101
+ - lib/golden_silk/result/diff.rb
102
+ - lib/golden_silk/result/no_effect.rb
103
+ - lib/golden_silk/spinner.rb
104
+ - lib/golden_silk/step/click.rb
105
+ - lib/golden_silk/step/visit.rb
55
106
  - lib/golden_silk/version.rb
56
107
  homepage: https://github.com/carols10cents/golden_silk
57
108
  licenses:
@@ -63,17 +114,17 @@ require_paths:
63
114
  - lib
64
115
  required_ruby_version: !ruby/object:Gem::Requirement
65
116
  requirements:
66
- - - '>='
117
+ - - ">="
67
118
  - !ruby/object:Gem::Version
68
119
  version: '0'
69
120
  required_rubygems_version: !ruby/object:Gem::Requirement
70
121
  requirements:
71
- - - '>='
122
+ - - ">"
72
123
  - !ruby/object:Gem::Version
73
- version: '0'
124
+ version: 1.3.1
74
125
  requirements: []
75
126
  rubyforge_project:
76
- rubygems_version: 2.2.2
127
+ rubygems_version: 2.4.3
77
128
  signing_key:
78
129
  specification_version: 4
79
130
  summary: Crawl your site to generate golden master tests.