har 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/har CHANGED
@@ -3,8 +3,7 @@
3
3
  require "har"
4
4
 
5
5
  begin
6
- ARGV << "-" if ARGV.empty?
7
6
  HAR::Viewer.new(ARGV).show
8
7
  rescue HAR::Error => ex
9
8
  abort "\n\n#{ex.message}"
10
- end
9
+ end
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.rubyforge_project = "har"
16
16
 
17
17
  s.add_dependency "json"
18
- s.add_dependency "json-schema", ">= 0.1.10"
18
+ s.add_dependency "json-schema", "= 0.1.12"
19
19
  s.add_dependency "launchy"
20
20
 
21
21
  s.add_development_dependency "rspec", "~> 2.0"
@@ -1,3 +1,3 @@
1
1
  module HAR
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -10,17 +10,17 @@ module HAR
10
10
  @running = false
11
11
  @options = parse(args)
12
12
 
13
- if @options[:validate]
14
- args = validate(args)
15
- end
16
-
17
- if args == ["-"]
13
+ if args == ["-"] || args.empty?
18
14
  progress("Reading HAR from stdin...") {
19
15
  @har = Archive.from_file $stdin
20
16
  }
17
+
18
+ validate_if_needed @har
21
19
  else
20
+ hars = validate_if_needed(args)
21
+
22
22
  progress("Merging HARs...") {
23
- @har = Archive.by_merging args
23
+ @har = Archive.by_merging hars
24
24
  }
25
25
  end
26
26
  end
@@ -33,12 +33,16 @@ module HAR
33
33
 
34
34
  private
35
35
 
36
- def validate(hars)
36
+ def validate_if_needed(hars)
37
+ return hars unless @options[:validate]
38
+
37
39
  progress("Validating archives...") {
38
- hars = hars.map { |path| Archive.from_file(path) }
39
- hars.each { |h| h.validate! }
40
+ Array(hars).map { |har|
41
+ har = har.kind_of?(Archive) ? har : Archive.from_file(har)
42
+ har.validate!
40
43
 
41
- hars
44
+ har
45
+ }
42
46
  }
43
47
  end
44
48
 
@@ -7,8 +7,8 @@ module HAR
7
7
  it "has sensible defaults" do
8
8
  v = Viewer.new([google_path])
9
9
 
10
- v.options[:port] == 1234
11
- v.options[:validate] == true
10
+ v.options[:port].should == 9292
11
+ v.options[:validate].should be_false
12
12
  end
13
13
 
14
14
  it "parses the port option" do
@@ -26,9 +26,15 @@ module HAR
26
26
  lambda { Viewer.new(["--validate", *all_hars]) }.should raise_error(ValidationError)
27
27
  end
28
28
 
29
+ it "validates HARs read from stdin if asked to" do
30
+ with_stdin_replaced_by(har_path("bad")) do
31
+ lambda { Viewer.new(["--validate", "-"]) }.should raise_error(ValidationError)
32
+ end
33
+ end
34
+
29
35
  it "has a merged archive" do
30
36
  Viewer.new(good_hars).har.should be_kind_of(Archive)
31
37
  end
32
38
 
33
39
  end
34
- end
40
+ end
@@ -34,6 +34,18 @@ module HAR
34
34
  def good_hars
35
35
  all_hars.reject { |e| e =~ /bad/ }
36
36
  end
37
+
38
+ def with_stdin_replaced_by(file_path)
39
+ stdin = $stdin
40
+ begin
41
+ File.open(file_path, "r") { |io|
42
+ $stdin = io
43
+ yield
44
+ }
45
+ ensure
46
+ $stdin = stdin
47
+ end
48
+ end
37
49
  end
38
50
  end
39
51
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: har
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.5
5
+ version: 0.0.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jari Bakken
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-12 00:00:00 +01:00
13
+ date: 2011-02-24 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -30,9 +30,9 @@ dependencies:
30
30
  requirement: &id002 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
- - - ">="
33
+ - - "="
34
34
  - !ruby/object:Gem::Version
35
- version: 0.1.10
35
+ version: 0.1.12
36
36
  type: :runtime
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
@@ -257,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
257
257
  requirements: []
258
258
 
259
259
  rubyforge_project: har
260
- rubygems_version: 1.5.0
260
+ rubygems_version: 1.5.2
261
261
  signing_key:
262
262
  specification_version: 3
263
263
  summary: Ruby library to work with HTTP archives