jsmestad-stale_fish 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,16 @@
1
1
  = Stale Fish
2
2
 
3
- This gem provides a method for keeping your fixtures in sync with their sources. This will prevent the scenario where your build is broken in production, but CI has a green build to do outdated fixture data.
3
+ This gem provides a method for keeping your fixtures in sync with their sources. This will prevent the scenario where your build is broken in production, but CI has a green build to do outdated fixture data. StaleFish also allows for FakeWeb integration and URI management.
4
+
5
+ == Features
6
+
7
+ * Fixture update frequency uses the ActiveSupport relative time DSL
8
+ * Versioned configuration file & fixtures means fixtures are only updated once per project.
9
+ * Manage FakeWeb stubbed URI's through StaleFish
10
+ * Automatic detection for Rails & Rack apps (default configuration locations)
11
+ * Test Framework agnostic (tested with Test::Unit & RSpec)
12
+ * Update all fixtures, specified fixtures, or forced update are all supported through the StaleFish.update_stale(*args) method
13
+ * Fixtures are ONLY updated when a valid HTTP request is made, if server returns anything other than 200, an error is thrown failing the tests.
4
14
 
5
15
  == How To
6
16
 
@@ -67,6 +77,10 @@ For all tests add the following to test_helper.rb
67
77
 
68
78
  View the wiki: http://wiki.github.com/jsmestad/stale_fish
69
79
 
80
+ == Thanks
81
+
82
+ Paul Sadauskas for his work on Resourceful (used by StaleFish to provide accurate http handling when updating fixtures)
83
+
70
84
  == Copyright
71
85
 
72
86
  Copyright (c) 2009 Justin Smestad. See LICENSE for details.
data/Rakefile CHANGED
@@ -5,14 +5,14 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "stale_fish"
8
- gem.summary = %Q{keeps fixtures synchronized with sources to prevent outdated fixtures going undetected. }
8
+ gem.summary = %Q{ keeps fixtures synchronized with sources to prevent outdated fixtures going undetected. }
9
9
  gem.email = "justin.smestad@gmail.com"
10
10
  gem.homepage = "http://github.com/jsmestad/stale_fish"
11
11
  gem.authors = ["Justin Smestad"]
12
12
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
13
 
14
14
  gem.add_dependency "fakeweb", ">= 1.2.4"
15
- gem.add_dependency "rio", ">= 0.4.2"
15
+ gem.add_dependency "resourceful", "~> 0.6.1"
16
16
  gem.add_dependency "activesupport", ">= 2.1.2"
17
17
  end
18
18
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.1.2
@@ -3,7 +3,7 @@ require 'ftools'
3
3
  require 'yaml'
4
4
  require 'rubygems'
5
5
  require 'activesupport' # only used for time helpers
6
- require 'rio'
6
+ require 'resourceful'
7
7
  begin
8
8
  require "fakeweb"
9
9
  rescue LoadError
@@ -13,23 +13,27 @@ end
13
13
  module StaleFish
14
14
  # no one likes stale fish.
15
15
 
16
+ class FixtureUpdateFailure < StandardError; end
17
+ class MalformedSourceURL < StandardError; end
18
+
16
19
  class << self
17
20
  attr_accessor :use_fakeweb
18
21
  attr_accessor :config_path
19
22
  attr_accessor :yaml
20
23
  attr_accessor :configuration
24
+ attr_accessor :http
21
25
  end
22
26
 
23
27
  self.use_fakeweb = false
28
+ self.http = Resourceful::HttpAccessor.new
24
29
 
25
30
  def self.valid_path?
26
- return false if config_path.nil?
27
- File.exist?(config_path)
31
+ !config_path.nil? ? File.exist?(config_path) : false
28
32
  end
29
33
 
30
34
  def self.update_stale(*args)
31
35
  # check each file for update
32
- load_yaml #if self.yaml.nil?
36
+ load_yaml if self.yaml.nil?
33
37
  stale = flag_stale(args)
34
38
  process(stale)
35
39
  write_yaml
@@ -37,28 +41,22 @@ module StaleFish
37
41
  end
38
42
 
39
43
  def self.register_uri(source_uri, response)
40
- if use_fakeweb && !FakeWeb.registered_uri?(source_uri)
41
- FakeWeb.register_uri(:any, source_uri, :body => response)
42
- end
44
+ FakeWeb.register_uri(:any, source_uri, :body => response) if use_fakeweb && !FakeWeb.registered_uri?(source_uri)
43
45
  end
44
46
 
45
47
  def self.load_yaml
46
- if valid_path?
47
- self.yaml = YAML.load_file(config_path)
48
- raise YAML::Error, 'missing stale root element' unless self.yaml['stale']
49
-
50
- # Grab Configuration from YAML
51
- configuration = self.yaml['stale'].delete('configuration')
52
- use_fakeweb = (@configuration['use_fakeweb'] || false) unless configuration.nil?
53
-
54
- # Process remaining nodes as items
55
- self.yaml['stale'].each do |key, value|
56
- %w{ filepath frequency source }.each do |field|
57
- raise YAML::Error, "missing #{field} node for #{key}" unless self.yaml['stale'][key][field]
58
- end
59
- end
60
- else
61
- raise Errno::ENOENT, 'invalid path, please set StaleFish.config_path than ensure StaleFish.valid_path? is true'
48
+ raise Errno::ENOENT, 'invalid path, please set StaleFish.config_path than ensure StaleFish.valid_path? is true' unless valid_path?
49
+
50
+ self.yaml = YAML.load_file(config_path)
51
+ raise YAML::Error, 'missing stale root element' unless self.yaml['stale']
52
+
53
+ # Grab Configuration from YAML
54
+ self.configuration = self.yaml['stale'].delete('configuration')
55
+ use_fakeweb = (configuration['use_fakeweb'] || false) unless configuration.nil?
56
+
57
+ # Process remaining nodes as items
58
+ self.yaml['stale'].each do |key, value|
59
+ %w{ filepath frequency source }.each { |field| raise YAML::Error, "missing #{field} node for #{key}" unless value[field] }
62
60
  end
63
61
  end
64
62
 
@@ -69,27 +67,27 @@ protected
69
67
  stale, scope = {}, self.yaml['stale']
70
68
  scope.each do |key, value|
71
69
  if args.empty?
72
- if scope[key]['updated'].blank?
73
- stale.merge!({key => scope[key]})
70
+ if value['updated'].blank?
71
+ stale.merge!({key => value})
74
72
  else
75
- last_modified = scope[key]['updated']
76
- update_on = DateTime.now + eval(scope[key]['frequency'])
73
+ last_modified = value['updated']
74
+ update_on = DateTime.now + eval(value['frequency'])
77
75
  if last_modified > update_on
78
- stale.merge!({key => scope[key]})
76
+ stale.merge!({key => value})
79
77
  else
80
- register_uri(scope[key]['source'], scope[key]['filepath'])
78
+ register_uri(value['source'], value['filepath'])
81
79
  end
82
80
  end
83
81
  else
84
- last_modified = scope[key]['updated']
85
- update_on = DateTime.now + eval(scope[key]['frequency'])
82
+ last_modified = value['updated']
83
+ update_on = DateTime.now + eval(value['frequency'])
86
84
  if force == true
87
- stale.merge!({key => scope[key]}) if args.include?(key)
85
+ stale.merge!({key => value}) if args.include?(key)
88
86
  else
89
- if args.include?(key) && (scope[key]['updated'].blank? || last_modified > update_on)
90
- stale.merge!({key => scope[key]})
87
+ if args.include?(key) && (value['updated'].blank? || last_modified > update_on)
88
+ stale.merge!({key => value})
91
89
  else
92
- register_uri(scope[key]['source'], scope[key]['filepath'])
90
+ register_uri(value['source'], value['filepath'])
93
91
  end
94
92
  end
95
93
  end
@@ -101,9 +99,17 @@ protected
101
99
  FakeWeb.allow_net_connect = true if use_fakeweb
102
100
 
103
101
  fixtures.each do |key, value|
104
- rio(fixtures[key]['source']) > rio(fixtures[key]['filepath'])
105
- register_uri(fixtures[key]['source'], fixtures[key]['filepath'])
106
- update_fixture(key)
102
+ begin
103
+ @response = http.resource(value['source']).get
104
+ File.open(value['filepath'], 'w') { |f| f.write @response.body.to_s }
105
+
106
+ update_fixture(key)
107
+ rescue Resourceful::UnsuccessfulHttpRequestError
108
+ raise FixtureUpdateFailure, "#{key}'s source: #{value['source']} returned unsuccessfully."
109
+ rescue ArgumentError
110
+ raise MalformedSourceURL, "#{key}'s source: #{value['source']} is not a valid URL path. Most likely it's missing a trailing slash."
111
+ end
112
+ register_uri(value['source'], value['filepath'])
107
113
  end
108
114
 
109
115
  FakeWeb.allow_net_connect = false if use_fakeweb
@@ -2,11 +2,11 @@
2
2
  stale:
3
3
  yahoo:
4
4
  filepath: ./tmp/yahoo.html
5
- source: http://www.yahoo.com
5
+ source: http://www.yahoo.com/
6
6
  updated:
7
7
  frequency: 1.day
8
8
  google:
9
9
  filepath: ./tmp/google.html
10
- source: http://www.google.com
10
+ source: http://www.google.com/
11
11
  updated:
12
12
  frequency: 2.weeks
@@ -3,10 +3,10 @@ stale:
3
3
  yahoo:
4
4
  filepath: ./tmp/yahoo.html
5
5
  frequency: 1.day
6
- updated: 2009-09-14 00:47:54 -06:00
7
- source: http://www.yahoo.com
6
+ updated: 2009-09-15T11:58:51-06:00
7
+ source: http://www.yahoo.com/
8
8
  google:
9
9
  filepath: ./tmp/google.html
10
10
  frequency: 2.weeks
11
- updated: 2009-09-14 00:47:54 -06:00
12
- source: http://www.google.com
11
+ updated: 2009-09-15T11:58:51-06:00
12
+ source: http://www.google.com/
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{stale_fish}
8
- s.version = "1.1.1"
8
+ s.version = "1.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Justin Smestad"]
@@ -49,16 +49,16 @@ Gem::Specification.new do |s|
49
49
 
50
50
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
51
  s.add_runtime_dependency(%q<fakeweb>, [">= 1.2.4"])
52
- s.add_runtime_dependency(%q<rio>, [">= 0.4.2"])
52
+ s.add_runtime_dependency(%q<resourceful>, ["~> 0.6.1"])
53
53
  s.add_runtime_dependency(%q<activesupport>, [">= 2.1.2"])
54
54
  else
55
55
  s.add_dependency(%q<fakeweb>, [">= 1.2.4"])
56
- s.add_dependency(%q<rio>, [">= 0.4.2"])
56
+ s.add_dependency(%q<resourceful>, ["~> 0.6.1"])
57
57
  s.add_dependency(%q<activesupport>, [">= 2.1.2"])
58
58
  end
59
59
  else
60
60
  s.add_dependency(%q<fakeweb>, [">= 1.2.4"])
61
- s.add_dependency(%q<rio>, [">= 0.4.2"])
61
+ s.add_dependency(%q<resourceful>, ["~> 0.6.1"])
62
62
  s.add_dependency(%q<activesupport>, [">= 2.1.2"])
63
63
  end
64
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsmestad-stale_fish
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Smestad
@@ -23,14 +23,14 @@ dependencies:
23
23
  version: 1.2.4
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
- name: rio
26
+ name: resourceful
27
27
  type: :runtime
28
28
  version_requirement:
29
29
  version_requirements: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 0.4.2
33
+ version: 0.6.1
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: activesupport