jsmestad-stale_fish 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +27 -5
- data/VERSION +1 -1
- data/lib/stale_fish.rb +52 -5
- data/spec/fixtures/stale_fish_fakeweb.yml +12 -0
- data/spec/stale_fish_spec.rb +32 -3
- data/stale_fish.gemspec +64 -0
- metadata +6 -3
data/README.rdoc
CHANGED
@@ -7,8 +7,10 @@ This gem provides a method for keeping your fixtures in sync with their sources.
|
|
7
7
|
Simply drop in a YAML file in your application (for rails, RAILS_ROOT/config/stale_fish.yml is preferred) and issue the following commands.
|
8
8
|
|
9
9
|
A sample YAML file:
|
10
|
-
|
11
|
-
stale:
|
10
|
+
|
11
|
+
stale:
|
12
|
+
configuration:
|
13
|
+
use_fakeweb: true
|
12
14
|
yahoo:
|
13
15
|
filepath: ./tmp/yahoo.html
|
14
16
|
source: http://www.yahoo.com
|
@@ -24,17 +26,17 @@ Specify one block for every fixture you would like to update. The frequency fiel
|
|
24
26
|
|
25
27
|
=== RSpec
|
26
28
|
|
27
|
-
For a single test
|
29
|
+
For a single test add it to a before block
|
28
30
|
|
29
31
|
describe UsersController do
|
30
32
|
before do
|
31
33
|
StaleFish.load_config = "#{RAILS_ROOT}/config/stale_fish.yml"
|
32
|
-
StaleFish.update_stale
|
34
|
+
StaleFish.update_stale("facebook", "yahoo")
|
33
35
|
end
|
34
36
|
....
|
35
37
|
end
|
36
38
|
|
37
|
-
For all tests
|
39
|
+
For all tests add the following to spec_helper.rb
|
38
40
|
|
39
41
|
Spec::Runner.configure do |config|
|
40
42
|
...
|
@@ -45,6 +47,26 @@ For all tests:
|
|
45
47
|
....
|
46
48
|
end
|
47
49
|
|
50
|
+
=== Test::Unit
|
51
|
+
|
52
|
+
For all tests add the following to test_helper.rb
|
53
|
+
|
54
|
+
class Test::Unit::TestCase
|
55
|
+
...
|
56
|
+
self.use_transactional_fixtures = true
|
57
|
+
self.use_instantiated_fixtures = false
|
58
|
+
...
|
59
|
+
setup do
|
60
|
+
StaleFish.load_config = "#{RAILS_ROOT}/config/stale_fish.yml"
|
61
|
+
StaleFish.update_stale
|
62
|
+
end
|
63
|
+
...
|
64
|
+
end
|
65
|
+
|
66
|
+
== More Info
|
67
|
+
|
68
|
+
View the wiki: http://wiki.github.com/jsmestad/stale_fish
|
69
|
+
|
48
70
|
== Copyright
|
49
71
|
|
50
72
|
Copyright (c) 2009 Justin Smestad. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/lib/stale_fish.rb
CHANGED
@@ -4,9 +4,23 @@ require 'yaml'
|
|
4
4
|
require 'rubygems'
|
5
5
|
require 'activesupport' # only used for time helpers
|
6
6
|
require 'rio'
|
7
|
+
begin
|
8
|
+
require "fakeweb"
|
9
|
+
rescue LoadError
|
10
|
+
|
11
|
+
end
|
7
12
|
|
8
13
|
module StaleFish
|
9
14
|
# no one likes stale fish.
|
15
|
+
def self.use_fakeweb=(enabled)
|
16
|
+
@use_fakeweb = enabled
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.use_fakeweb
|
20
|
+
@use_fakeweb
|
21
|
+
end
|
22
|
+
|
23
|
+
self.use_fakeweb = false
|
10
24
|
|
11
25
|
def self.config_path=(path)
|
12
26
|
@config_path = path
|
@@ -23,13 +37,27 @@ module StaleFish
|
|
23
37
|
|
24
38
|
def self.update_stale(*args)
|
25
39
|
# check each file for update
|
26
|
-
load_yaml
|
40
|
+
load_yaml if self.yaml.nil?
|
27
41
|
stale = flag_stale(args)
|
28
42
|
process(stale)
|
29
43
|
write_yaml
|
30
44
|
return stale.size
|
31
45
|
end
|
32
46
|
|
47
|
+
def self.yaml=(data)
|
48
|
+
@yaml = data
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.yaml
|
52
|
+
!@yaml.nil? ? @yaml['stale'] : @yaml
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.register_uri(source_uri, response)
|
56
|
+
if self.use_fakeweb && !FakeWeb.registered_uri?(source_uri)
|
57
|
+
FakeWeb.register_uri(:any, source_uri, :body => response)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
33
61
|
def self.load_yaml
|
34
62
|
if valid_path?
|
35
63
|
@yaml = YAML.load_file(@config_path)
|
@@ -43,6 +71,12 @@ protected
|
|
43
71
|
|
44
72
|
def self.check_syntax
|
45
73
|
raise YAML::Error, 'missing stale root element' unless @yaml['stale']
|
74
|
+
|
75
|
+
# Grab Configuration from YAML
|
76
|
+
@configuration = @yaml['stale'].delete('configuration')
|
77
|
+
self.use_fakeweb = (@configuration['use_fakeweb'] || false) unless @configuration.nil?
|
78
|
+
|
79
|
+
# Process remaining nodes as items
|
46
80
|
@yaml['stale'].each do |key, value|
|
47
81
|
%w{ filepath frequency source }.each do |field|
|
48
82
|
raise YAML::Error, "missing #{field} node for #{key}" unless @yaml['stale'][key][field]
|
@@ -52,15 +86,19 @@ protected
|
|
52
86
|
|
53
87
|
def self.flag_stale(args)
|
54
88
|
force = args.pop[:force] if args.last.is_a?(Hash)
|
55
|
-
stale, scope = {},
|
89
|
+
stale, scope = {}, self.yaml
|
56
90
|
scope.each do |key, value|
|
57
91
|
if args.empty?
|
58
92
|
if scope[key]['updated'].blank?
|
59
|
-
stale.merge!({key => scope[key]})
|
93
|
+
stale.merge!({key => scope[key]})
|
60
94
|
else
|
61
95
|
last_modified = scope[key]['updated']
|
62
96
|
update_on = DateTime.now + eval(scope[key]['frequency'])
|
63
|
-
|
97
|
+
if last_modified > update_on
|
98
|
+
stale.merge!({key => scope[key]})
|
99
|
+
else
|
100
|
+
self.register_uri(scope[key]['source'], scope[key]['filepath'])
|
101
|
+
end
|
64
102
|
end
|
65
103
|
else
|
66
104
|
last_modified = scope[key]['updated']
|
@@ -68,7 +106,11 @@ protected
|
|
68
106
|
if force == true
|
69
107
|
stale.merge!({key => scope[key]}) if args.include?(key)
|
70
108
|
else
|
71
|
-
|
109
|
+
if args.include?(key) && (scope[key]['updated'].blank? || last_modified > update_on)
|
110
|
+
stale.merge!({key => scope[key]})
|
111
|
+
else
|
112
|
+
self.register_uri(scope[key]['source'], scope[key]['filepath'])
|
113
|
+
end
|
72
114
|
end
|
73
115
|
end
|
74
116
|
end
|
@@ -76,10 +118,15 @@ protected
|
|
76
118
|
end
|
77
119
|
|
78
120
|
def self.process(fixtures)
|
121
|
+
FakeWeb.allow_net_connect = true if self.use_fakeweb
|
122
|
+
|
79
123
|
fixtures.each do |key, value|
|
80
124
|
rio(fixtures[key]['source']) > rio(fixtures[key]['filepath'])
|
125
|
+
self.register_uri(fixtures[key]['source'], fixtures[key]['filepath'])
|
81
126
|
update_fixture(key)
|
82
127
|
end
|
128
|
+
|
129
|
+
FakeWeb.allow_net_connect = false if self.use_fakeweb
|
83
130
|
end
|
84
131
|
|
85
132
|
def self.update_fixture(key)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
---
|
2
|
+
stale:
|
3
|
+
yahoo:
|
4
|
+
filepath: ./tmp/yahoo.html
|
5
|
+
frequency: 1.day
|
6
|
+
updated: 2009-09-14 00:47:54 -06:00
|
7
|
+
source: http://www.yahoo.com
|
8
|
+
google:
|
9
|
+
filepath: ./tmp/google.html
|
10
|
+
frequency: 2.weeks
|
11
|
+
updated: 2009-09-14 00:47:54 -06:00
|
12
|
+
source: http://www.google.com
|
data/spec/stale_fish_spec.rb
CHANGED
@@ -22,6 +22,7 @@ describe "StaleFish" do
|
|
22
22
|
StaleFish.config_path = @valid_yaml
|
23
23
|
lambda { StaleFish.load_yaml }.should_not raise_error(YAML::Error)
|
24
24
|
end
|
25
|
+
|
25
26
|
end
|
26
27
|
|
27
28
|
context "after loading the config" do
|
@@ -29,7 +30,7 @@ describe "StaleFish" do
|
|
29
30
|
FileUtils.cp(@valid_yaml, File.dirname(__FILE__)+"/fixtures/stale_fish.orig.yml")
|
30
31
|
StaleFish.config_path = @valid_yaml
|
31
32
|
StaleFish.valid_path?.should == true
|
32
|
-
StaleFish.load_yaml
|
33
|
+
StaleFish.load_yaml
|
33
34
|
end
|
34
35
|
|
35
36
|
it "should update all stale fixtures" do
|
@@ -45,11 +46,39 @@ describe "StaleFish" do
|
|
45
46
|
StaleFish.update_stale('google', :force => true).should == 1
|
46
47
|
end
|
47
48
|
|
48
|
-
|
49
|
+
it "should notify user, and rollback, if source is no longer valid"
|
49
50
|
|
50
51
|
after(:each) do
|
51
52
|
FileUtils.mv(@valid_yaml, File.dirname(__FILE__)+"/../tmp/stale_fish.test.yml")
|
52
|
-
FileUtils.mv(File.dirname(__FILE__)+"/fixtures/stale_fish.orig.yml", @valid_yaml)
|
53
|
+
FileUtils.mv(File.dirname(__FILE__)+"/fixtures/stale_fish.orig.yml", @valid_yaml)
|
54
|
+
StaleFish.yaml = nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "with FakeWeb" do
|
59
|
+
before(:each) do
|
60
|
+
@fakeweb_yaml = File.dirname(__FILE__) + '/fixtures/stale_fish_fakeweb.yml'
|
61
|
+
StaleFish.config_path = @fakeweb_yaml
|
62
|
+
StaleFish.valid_path?.should == true
|
63
|
+
StaleFish.load_yaml
|
64
|
+
StaleFish.use_fakeweb = true
|
65
|
+
StaleFish.use_fakeweb.should == true
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should register any FakeWeb URI's" do
|
69
|
+
StaleFish.register_uri("http://www.google.com", "some shit")
|
70
|
+
FakeWeb.registered_uri?("http://www.google.com").should == true
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should turn off FakeWeb.allow_net_connect to process stale fixtures" do
|
74
|
+
FakeWeb.allow_net_connect = false
|
75
|
+
lambda { StaleFish.update_stale(:force => true) }.should_not raise_error
|
76
|
+
lambda { StaleFish.update_stale(:force => true) }.should_not change { FakeWeb.allow_net_connect? }
|
77
|
+
end
|
78
|
+
|
79
|
+
after(:each) do
|
80
|
+
StaleFish.yaml = nil
|
53
81
|
end
|
54
82
|
end
|
83
|
+
|
55
84
|
end
|
data/stale_fish.gemspec
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{stale_fish}
|
8
|
+
s.version = "1.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Justin Smestad"]
|
12
|
+
s.date = %q{2009-09-14}
|
13
|
+
s.email = %q{justin.smestad@gmail.com}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE",
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"lib/stale_fish.rb",
|
26
|
+
"spec/fixtures/google.html",
|
27
|
+
"spec/fixtures/malformed_stale_fish.yml",
|
28
|
+
"spec/fixtures/stale_fish.yml",
|
29
|
+
"spec/fixtures/stale_fish_fakeweb.yml",
|
30
|
+
"spec/fixtures/yahoo.html",
|
31
|
+
"spec/spec_helper.rb",
|
32
|
+
"spec/stale_fish_spec.rb",
|
33
|
+
"stale_fish.gemspec",
|
34
|
+
"tmp/.gitignore"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/jsmestad/stale_fish}
|
37
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.5}
|
40
|
+
s.summary = %q{keeps fixtures synchronized with sources to prevent outdated fixtures going undetected.}
|
41
|
+
s.test_files = [
|
42
|
+
"spec/spec_helper.rb",
|
43
|
+
"spec/stale_fish_spec.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_runtime_dependency(%q<fakeweb>, [">= 1.2.4"])
|
52
|
+
s.add_runtime_dependency(%q<rio>, [">= 0.4.2"])
|
53
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 2.1.2"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<fakeweb>, [">= 1.2.4"])
|
56
|
+
s.add_dependency(%q<rio>, [">= 0.4.2"])
|
57
|
+
s.add_dependency(%q<activesupport>, [">= 2.1.2"])
|
58
|
+
end
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<fakeweb>, [">= 1.2.4"])
|
61
|
+
s.add_dependency(%q<rio>, [">= 0.4.2"])
|
62
|
+
s.add_dependency(%q<activesupport>, [">= 2.1.2"])
|
63
|
+
end
|
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.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Smestad
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-14 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -62,12 +62,15 @@ files:
|
|
62
62
|
- spec/fixtures/google.html
|
63
63
|
- spec/fixtures/malformed_stale_fish.yml
|
64
64
|
- spec/fixtures/stale_fish.yml
|
65
|
+
- spec/fixtures/stale_fish_fakeweb.yml
|
65
66
|
- spec/fixtures/yahoo.html
|
66
67
|
- spec/spec_helper.rb
|
67
68
|
- spec/stale_fish_spec.rb
|
69
|
+
- stale_fish.gemspec
|
68
70
|
- tmp/.gitignore
|
69
71
|
has_rdoc: false
|
70
72
|
homepage: http://github.com/jsmestad/stale_fish
|
73
|
+
licenses:
|
71
74
|
post_install_message:
|
72
75
|
rdoc_options:
|
73
76
|
- --charset=UTF-8
|
@@ -88,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
91
|
requirements: []
|
89
92
|
|
90
93
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.
|
94
|
+
rubygems_version: 1.3.5
|
92
95
|
signing_key:
|
93
96
|
specification_version: 3
|
94
97
|
summary: keeps fixtures synchronized with sources to prevent outdated fixtures going undetected.
|