page_speed 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.8.7-ree # (current default)
4
+ - 1.9.2
5
+ script: "bundle exec rspec spec/"
@@ -1,7 +1,16 @@
1
1
  require "page_speed/version"
2
2
 
3
- require 'json'
4
3
  require 'open-uri'
4
+ require 'json' unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
5
+
6
+ # Hack that allows us to avoid certification validations in Ruby Enterprise Editions
7
+ require 'openssl'
8
+ module OpenSSL
9
+ module SSL
10
+ remove_const :VERIFY_PEER
11
+ end
12
+ end
13
+ OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
5
14
 
6
15
  API_URL = "https://www.googleapis.com/pagespeedonline/v1/runPagespeed"
7
16
 
@@ -23,7 +32,6 @@ module PageSpeed
23
32
 
24
33
  rescue OpenURI::HTTPError
25
34
  puts "The API you used is not correct. Use the -k option to replace it."
26
- puts ""
27
35
  reset_api_key
28
36
  help
29
37
 
@@ -63,7 +71,8 @@ module PageSpeed
63
71
  begin
64
72
  get_api_key
65
73
  true
66
- rescue Exception
74
+ rescue Exception => e
75
+ p e
67
76
  false
68
77
  end
69
78
  end
@@ -120,12 +129,8 @@ module PageSpeed
120
129
  end
121
130
 
122
131
  def api_key_path
123
- dir = testing ? "/tmp" : File.expand_path("~")
124
- dir + "/.page_speed"
125
- end
126
-
127
- def testing
128
- ! defined?(ENV['page_speed_env']).nil? && ENV['page_speed_env'] == "test"
132
+ folder = ENV["TESTING"] ? "/tmp" : "~"
133
+ File.expand_path("#{folder}/.page_speed")
129
134
  end
130
135
  end
131
136
  end
@@ -1,3 +1,3 @@
1
1
  module PageSpeed
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.files = `git ls-files`.split("\n")
22
22
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
23
  s.require_paths = ["lib"]
24
- s.add_development_dependency "rspec", "2.3.0"
25
- s.add_development_dependency "ZenTest", "4.4.2"
24
+ s.add_dependency "json"
25
+ s.add_development_dependency "rspec"
26
+ s.add_development_dependency "ZenTest"
26
27
  end
@@ -1,11 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- ENV['page_speed_env'] = "test"
4
3
  API_KEY = "AIzaSyCT0PgAW-FjLF0Nfx81DqU6laCSiXkIHFs"
4
+ TMP_FILE = "/tmp/.page_speed"
5
5
 
6
6
  describe PageSpeed do
7
7
  before do
8
- File.open("/tmp/.page_speed", 'w') {|f| f.write(API_KEY) } # Use a correct API KEY
8
+ ENV["TESTING"] = "TRUE"
9
+ File.open(TMP_FILE, 'w') {|f| f.write(API_KEY) } # Use a correct API KEY
9
10
  end
10
11
 
11
12
  it "should point to help when no parameter is provided" do
@@ -51,7 +52,7 @@ describe PageSpeed do
51
52
 
52
53
  it "should success with a URL without www" do
53
54
  result = `bin/page_speed google.com`
54
- result.should include("Google Page Speed for http://google.com: 98 (Desktop) / 96 (Mobile)")
55
+ result.should include("Google Page Speed for http://google.com: 98 (Desktop) / 97 (Mobile)")
55
56
  end
56
57
 
57
58
  it "should success with a URL with www" do
@@ -62,14 +63,14 @@ describe PageSpeed do
62
63
 
63
64
  context "API key control" do
64
65
  it "should prompt the API key when is not found" do
65
- File.delete("/tmp/.page_speed")
66
+ File.delete(TMP_FILE)
66
67
  result = `bin/page_speed google.com`
67
68
  result.should include("PI key not set. Use the -k option to set the key.")
68
69
  end
69
70
 
70
71
  context "when API key is corrupted" do
71
72
  before do
72
- File.open("/tmp/.page_speed", 'w') {|f| f.write(API_KEY.chop) } # Use a corrupt API KEY
73
+ File.open(TMP_FILE, 'w') {|f| f.write(API_KEY.chop) } # Use a corrupt API KEY
73
74
  @result = `bin/page_speed google.com`
74
75
  end
75
76
 
@@ -79,12 +80,31 @@ describe PageSpeed do
79
80
 
80
81
  it "should have deleted the file where the API key is and ask for a new one" do
81
82
  @result = `bin/page_speed google.com`
82
- @result.should include("PI key not set. Use the -k option to set the key.")
83
+ @result.should include("API key not set. Use the -k option to set the key.")
84
+ end
85
+
86
+ it "should have indeed deleted the file" do
87
+ @result = `bin/page_speed google.com`
88
+ File.exists?(TMP_FILE).should == false
83
89
  end
84
90
  end
85
91
  end
86
92
 
87
93
  context "key" do
94
+ before do
95
+ @result = `bin/page_speed -k DO_THE_CUCA`
96
+ end
97
+
98
+ it "should be set and the user should get feedback" do
99
+ @result.should include("API key set.")
100
+ end
101
+
102
+ it "should be correctly set" do
103
+ PageSpeed::get_api_key.should == "DO_THE_CUCA"
104
+ end
105
+ end
88
106
 
107
+ after do
108
+ File.delete(TMP_FILE) if File.exists?(TMP_FILE)
89
109
  end
90
110
  end
metadata CHANGED
@@ -1,53 +1,60 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: page_speed
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
4
5
  prerelease:
5
- version: 0.1.4
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Albert Bellonch
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-09-26 00:00:00 +02:00
14
- default_executable: page_speed
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: rspec
12
+ date: 2011-10-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: &70151869961940 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
18
23
  prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: *70151869961940
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70151869959960 !ruby/object:Gem::Requirement
20
28
  none: false
21
- requirements:
22
- - - "="
23
- - !ruby/object:Gem::Version
24
- version: 2.3.0
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
25
33
  type: :development
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: ZenTest
29
34
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
35
+ version_requirements: *70151869959960
36
+ - !ruby/object:Gem::Dependency
37
+ name: ZenTest
38
+ requirement: &70151869959460 !ruby/object:Gem::Requirement
31
39
  none: false
32
- requirements:
33
- - - "="
34
- - !ruby/object:Gem::Version
35
- version: 4.4.2
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
36
44
  type: :development
37
- version_requirements: *id002
38
- description: "-"
39
- email:
45
+ prerelease: false
46
+ version_requirements: *70151869959460
47
+ description: ! '-'
48
+ email:
40
49
  - albert@itnig.net
41
- executables:
50
+ executables:
42
51
  - page_speed
43
52
  extensions: []
44
-
45
53
  extra_rdoc_files: []
46
-
47
- files:
54
+ files:
48
55
  - .gitignore
49
56
  - .rspec
50
- - .rvmrc
57
+ - .travis.yml
51
58
  - Gemfile
52
59
  - README.md
53
60
  - Rakefile
@@ -57,34 +64,30 @@ files:
57
64
  - page_speed.gemspec
58
65
  - spec/integration/page_speed_spec.rb
59
66
  - spec/spec_helper.rb
60
- has_rdoc: true
61
67
  homepage: http://itnig.net
62
68
  licenses: []
63
-
64
69
  post_install_message:
65
70
  rdoc_options: []
66
-
67
- require_paths:
71
+ require_paths:
68
72
  - lib
69
- required_ruby_version: !ruby/object:Gem::Requirement
73
+ required_ruby_version: !ruby/object:Gem::Requirement
70
74
  none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: "0"
75
- required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
80
  none: false
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: "0"
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
81
85
  requirements: []
82
-
83
86
  rubyforge_project: page_speed
84
- rubygems_version: 1.6.1
87
+ rubygems_version: 1.8.10
85
88
  signing_key:
86
89
  specification_version: 3
87
90
  summary: A simple port for Google Page Speed's scores
88
- test_files:
91
+ test_files:
89
92
  - spec/integration/page_speed_spec.rb
90
93
  - spec/spec_helper.rb
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm 1.9.2rvm 1.9.2