stale_fish 1.2.4 → 1.3.0.pre

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source :gemcutter
2
+
3
+ group :runtime do
4
+ gem 'fakeweb'
5
+ gem 'activesupport', :require => "active_support/core_ext/numeric/time"
6
+ end
7
+
8
+ group :test do
9
+ gem 'rspec', :require => 'spec'
10
+ gem 'rake'
11
+ gem 'bundler', '~> 0.9.5'
12
+ gem 'jeweler'
13
+ end
14
+
data/README.rdoc CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
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
4
 
5
+ == NOTICE
6
+
7
+ 1.3.x is a complete rewrite of the StaleFish utility. The API is based on: http://gist.github.com/308260
8
+
9
+ The information below has not been corrected or updated.
10
+
5
11
  == Features
6
12
 
7
13
  * Fixture update frequency uses the ActiveSupport relative time DSL
data/Rakefile CHANGED
@@ -1,21 +1,22 @@
1
- require 'rubygems'
2
1
  require 'rake'
2
+ require 'bundler'
3
3
 
4
4
  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 = "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
- gem.add_dependency "facets"
14
- gem.add_dependency "fakeweb", ">= 1.2.4"
15
- gem.add_dependency "resourceful", "~> 0.6.1"
16
- gem.add_dependency "activesupport", ">= 2.1.2"
13
+ bundle = Bundler::Definition.from_gemfile('Gemfile')
14
+ bundle.dependencies.each do |dep|
15
+ next unless dep.groups.include?(:runtime)
16
+ gem.add_dependency(dep.name, dep.version_requirements.to_s)
17
+ end
17
18
  end
18
-
19
+ Jeweler::GemcutterTasks.new
19
20
  rescue LoadError
20
21
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
22
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.4
1
+ 1.3.0.pre
@@ -0,0 +1,68 @@
1
+ module StaleFish
2
+ class Fixture
3
+ attr_accessor :name, :file, :last_updated_at
4
+ attr_accessor :update_interval, :update_string, :check_against, :request_type
5
+
6
+ def initialize(attributes={})
7
+ attributes.each do |key, value|
8
+ self.send("#{key}=", value)
9
+ end
10
+ end
11
+
12
+ def is_stale?
13
+ if (last_updated_at + update_interval) < Time.now
14
+ return true
15
+ else
16
+ return false
17
+ end
18
+ end
19
+
20
+ def update!
21
+ uri, type = URI.parse(check_against), request_type.downcase.to_sym
22
+ Net::HTTP.start(uri.host) { |http|
23
+ response = if type == :post
24
+ http.post(uri.path, uri.query)
25
+ else
26
+ http.get(uri.path)
27
+ end
28
+ write_response_to_file(response.body)
29
+ }
30
+
31
+ self.last_updated_at = Time.now
32
+ end
33
+
34
+ def register_lock!
35
+ uri, type = build_uri, request_type.downcase.to_sym
36
+ FakeWeb.register_uri(type, uri, :body => file)
37
+
38
+ return FakeWeb.registered_uri?(type, uri)
39
+ end
40
+
41
+ def to_yaml
42
+ # update_interval.inspect trick is to prevent Fixnum being written
43
+ yaml = <<-EOF
44
+ #{name}:
45
+ file: '#{file}'
46
+ update_interval: #{update_interval.inspect.gsub(/ /, '.')}
47
+ check_against: #{check_against}
48
+ request_type: #{request_type}
49
+ last_updated_at: #{last_updated_at}
50
+ EOF
51
+ return yaml
52
+ end
53
+
54
+ protected
55
+
56
+ def build_uri
57
+ if check_against =~ /:\d+/
58
+ Regexp.new(check_against, true)
59
+ else
60
+ check_against
61
+ end
62
+ end
63
+
64
+ def write_response_to_file(body)
65
+ File.open(file, "w") { |file| file.write(body) }
66
+ end
67
+ end
68
+ end
data/lib/stale_fish.rb CHANGED
@@ -1,54 +1,85 @@
1
- require 'singleton'
2
- require 'ftools'
1
+ #Rails 3: require 'active_support/core_ext/numeric/time'
2
+ require 'active_support'
3
+ require 'fakeweb'
3
4
  require 'yaml'
4
- require 'rubygems'
5
- require 'activesupport' # only used for time helpers
6
- require 'resourceful'
7
5
 
8
- require 'stale_fish/utility'
9
- require 'stale_fish/fixture_definition'
10
-
11
- begin
12
- require 'fakeweb'
13
- require 'stale_fish/fakeweb'
14
- rescue LoadError; end
6
+ require File.join(File.dirname(__FILE__), 'stale_fish', 'fixture')
15
7
 
16
8
  module StaleFish
17
9
  # no one likes stale fish.
18
-
19
- class FixtureUpdateFailure < StandardError; end
20
- class MalformedSourceURL < StandardError; end
21
-
22
10
  class << self
23
- attr_accessor :configuration
24
- attr_accessor :http
25
- attr_accessor :fixtures
26
- attr_accessor :force_flag
27
- end
28
11
 
29
- self.fixtures = []
30
- Utility.config_path = 'stale_fish.yml'
31
- self.http = Resourceful::HttpAccessor.new
12
+ def configuration=(config)
13
+ @configuration = config
14
+ end
32
15
 
33
- def self.update_stale(*args)
34
- # TODO move this to its own spot
35
- Utility.loader if self.fixtures.empty?
36
- self.force_flag = args.pop[:force] if args.last.is_a?(Hash)
16
+ def configuration
17
+ @configuration || if defined?(Rails)
18
+ File.join(Rails.root, 'spec', 'stale_fish.yml')
19
+ else
20
+ 'stale_fish.yml'
21
+ end
22
+ end
37
23
 
38
- stale = if args.empty?
39
- fixtures.select { |f| f.is_stale? }
40
- else
41
- fixtures.select { |f| f.is_stale? && args.include?(f.tag) }
42
- end
24
+ def update_stale(options={})
25
+ allow_requests
26
+ fixtures(options).each do |fixture|
27
+ if fixture.is_stale?
28
+ fixture.update!
29
+ end
30
+ end
31
+ block_requests
32
+ write
33
+ end
43
34
 
44
- stale.each do |fixture|
45
- fixture.update!
35
+ def update_stale!(options={})
36
+ allow_requests
37
+ fixtures(options).each do |fixture|
38
+ fixture.update!
39
+ end
40
+ block_requests
41
+ write
46
42
  end
47
43
 
48
- fixtures.each { |fixture| fixture.register_uri if StaleFish.use_fakeweb }
44
+ def fixtures(params=nil)
45
+ @fixtures ||= []
46
+ if params.is_a?(Hash)
47
+ if params[:only]
48
+ @fixtures.select { |f| params[:only].include?(f.name.to_sym) }
49
+ elsif params[:except]
50
+ @fixtures.select { |f| !params[:except].include?(f.name.to_sym) }
51
+ end
52
+ else
53
+ @fixtures
54
+ end
55
+ end
49
56
 
50
- Utility.writer
51
- return stale.size
52
- end
57
+ protected
58
+
59
+ def load
60
+ @fixtures = []
61
+ definitions = YAML::load(File.open(configuration))['stale'].symbolize_keys!
62
+ definitions.each do |key, definition|
63
+ self.fixtures << StaleFish::Fixture.new(definition.merge({:name => key.to_s}))
64
+ end
65
+ return fixtures
66
+ end
53
67
 
68
+ def write
69
+ updated_yaml = []
70
+ fixtures.each do |fixture|
71
+ updated_yaml << fixture.to_yaml
72
+ end
73
+ updated_yaml = { :stale => updated_yaml }
74
+ File.open(configuration, 'w') { |file| updated_yaml.to_yaml }
75
+ end
76
+
77
+ def allow_requests
78
+ FakeWeb.allow_net_connect = true
79
+ end
80
+
81
+ def block_requests
82
+ FakeWeb.allow_net_connect = false
83
+ end
84
+ end
54
85
  end
@@ -5,9 +5,9 @@ stale:
5
5
  file_path: ./tmp/yahoo.html
6
6
  source_url: http://www.yahoo.com/
7
7
  update_frequency: 1.day
8
- last_updated_at: 2009-09-25T17:31:11-06:00
8
+ last_updated_at: 2009-11-30T18:26:20-07:00
9
9
  google:
10
10
  file_path: ./tmp/google.html
11
11
  source_url: http://www.google.com/
12
12
  update_frequency: 2.weeks
13
- last_updated_at: 2009-09-25T17:31:11-06:00
13
+ last_updated_at: 2009-11-30T18:26:20-07:00
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,19 @@
1
- require 'spec'
2
-
1
+ Bundler.require(:default, :runtime, :test)
3
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
4
3
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+
5
5
  require 'stale_fish'
6
+ require 'spec'
7
+ require 'spec/autorun'
8
+
9
+ # Requires supporting files with custom matchers and macros, etc,
10
+ # in ./support/ and its subdirectories.
11
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
6
12
 
7
13
  Spec::Runner.configure do |config|
8
-
14
+
15
+ config.before :all do
16
+ StaleFish.configuration = nil
17
+ end
18
+
9
19
  end
File without changes
@@ -0,0 +1,14 @@
1
+ stale:
2
+ twitter:
3
+ file: 'timeline.json'
4
+ update_interval: 30.days
5
+ check_against: http://twitter.com/api/timeline
6
+ request_type: POST
7
+ last_updated_at:
8
+ gh_commits:
9
+ file: 'commits.xml'
10
+ update_interval: 3.days
11
+ check_against: http://api.github.com/commits.xml
12
+ request_type: GET
13
+ last_updated_at:
14
+
@@ -0,0 +1,123 @@
1
+ require File.join(File.dirname(__FILE__), *%w[.. spec_helper])
2
+
3
+ describe StaleFish::Fixture do
4
+ before do
5
+ @time = Time.now
6
+ @args = {
7
+ :name => 'commits',
8
+ :file => 'commit.json',
9
+ :last_updated_at => @time,
10
+ :update_interval => 2.days,
11
+ :check_against => 'http://google.com',
12
+ :request_type => 'GET'
13
+ }
14
+ end
15
+
16
+ context "#initialize" do
17
+ it "set the proper arguements" do
18
+ fixture = StaleFish::Fixture.new(@args)
19
+ @args.each do |key, value|
20
+ fixture.send(key).should == value
21
+ end
22
+ end
23
+ end
24
+
25
+ context "#is_stale?" do
26
+ before do
27
+ @stale_fixture = StaleFish::Fixture.new(:last_updated_at => 1.week.ago,
28
+ :update_interval => 1.day)
29
+ @fresh_fixture = StaleFish::Fixture.new(:last_updated_at => 1.day.from_now,
30
+ :update_interval => 1.day)
31
+ end
32
+
33
+ it "should return true when stale" do
34
+ @stale_fixture.is_stale?.should == true
35
+ end
36
+
37
+ it "should return false when fresh" do
38
+ @fresh_fixture.is_stale?.should == false
39
+ end
40
+ end
41
+
42
+ context "#update!" do
43
+ before do
44
+ @fixture = StaleFish::Fixture.new(:request_type => 'GET',
45
+ :check_against => 'http://google.com/index.html',
46
+ :file => 'index.html')
47
+ end
48
+
49
+ it "should update the fixture data" do
50
+ @fixture.should_receive(:write_response_to_file).once.and_return(true)
51
+ @fixture.update!
52
+ @fixture.last_updated_at.should be_a(Time)
53
+ end
54
+
55
+ it "should use Net::HTTP#get with a GET request_type"
56
+ it "should use Net::HTTP#post with a POST request_type"
57
+ end
58
+
59
+ context "#register_lock!" do
60
+ before do
61
+ @fixture = StaleFish::Fixture.new(:request_type => 'GET',
62
+ :check_against => 'http://google.com/index.html',
63
+ :file => 'index.html')
64
+ end
65
+
66
+ it "should add fakeweb register_uri" do
67
+ @fixture.register_lock!.should == true
68
+ end
69
+ end
70
+
71
+ context "#to_yaml" do
72
+ before do
73
+ @fixture = StaleFish::Fixture.new(:name => 'google',
74
+ :update_interval => 1.day,
75
+ :request_type => 'GET',
76
+ :check_against => 'http://google.com/index.html',
77
+ :file => 'index.html',
78
+ :last_updated_at => @time)
79
+ @proper_yaml =
80
+ <<-EOF
81
+ google:
82
+ file: 'index.html'
83
+ update_interval: 1.day
84
+ check_against: http://google.com/index.html
85
+ request_type: GET
86
+ last_updated_at: #{@time}
87
+ EOF
88
+ end
89
+
90
+ it "should have the proper schema" do
91
+ @fixture.to_yaml.should == @proper_yaml
92
+ end
93
+ end
94
+
95
+ context "#build_uri" do
96
+ before do
97
+ @fixture = StaleFish::Fixture.new(@args)
98
+ end
99
+
100
+ it "should parse anything with a port as a regular expression" do
101
+ @fixture.check_against = 'http://www.google.com:443/index.html'
102
+ @fixture.send(:build_uri).should be_a(Regexp)
103
+ end
104
+
105
+ it "should parse anything without a port as a string" do
106
+ @fixture.check_against = 'http://www.google.com/index.html'
107
+ @fixture.send(:build_uri).should be_a(String)
108
+ end
109
+ end
110
+
111
+ context "#write_response_to_file" do
112
+ before do
113
+ @fixture = StaleFish::Fixture.new(@args)
114
+ end
115
+
116
+ it "should update the passed in file" do
117
+ File.should_receive(:open).and_return(true)
118
+ @fixture.send(:write_response_to_file, 'this is a response')
119
+ end
120
+
121
+ it "should have failover with a bad response"
122
+ end
123
+ end
@@ -0,0 +1,124 @@
1
+ require File.join(File.dirname(__FILE__), *%w[.. spec_helper])
2
+
3
+ describe StaleFish do
4
+ before do
5
+ @stale_fixture = StaleFish::Fixture.new(:last_updated_at => 1.week.ago,
6
+ :update_interval => 1.day)
7
+ @fresh_fixture = StaleFish::Fixture.new(:last_updated_at => 1.day.from_now,
8
+ :update_interval => 1.day)
9
+ end
10
+
11
+ context ".configuration" do
12
+ it "should return a default path" do
13
+ StaleFish.configuration.should == 'stale_fish.yml'
14
+ end
15
+ end
16
+
17
+ context ".configuration=" do
18
+ it "should assign the path to the config file" do
19
+ StaleFish.configuration = '/someplace/stale_fish.yml'
20
+ StaleFish.configuration.should == '/someplace/stale_fish.yml'
21
+ end
22
+ end
23
+
24
+ context ".load" do
25
+ before do
26
+ test_yaml = File.join(File.dirname(__FILE__), '..', 'support', 'test.yml')
27
+ StaleFish.stub!(:configuration).and_return(test_yaml)
28
+ end
29
+
30
+ it "should build fixtures" do
31
+ StaleFish.send(:load).size.should == 2
32
+ StaleFish.fixtures.size.should == 2
33
+ end
34
+
35
+ end
36
+
37
+ context ".update_stale" do
38
+ before do
39
+ StaleFish.stub!(:fixtures).and_return([@stale_fixture,@fresh_fixture])
40
+ @stale_fixture.stub!(:update!).and_return(true)
41
+ @fresh_fixture.stub!(:update!).and_return(true)
42
+ StaleFish.should_receive(:write)
43
+ end
44
+
45
+ it "should only call update! on stale fixtures" do
46
+ @stale_fixture.should_receive(:update!).once
47
+ @fresh_fixture.should_not_receive(:update!)
48
+ StaleFish.update_stale
49
+ end
50
+
51
+ it "should block requests after completion" do
52
+ StaleFish.should_receive(:allow_requests)
53
+ StaleFish.should_receive(:block_requests)
54
+ StaleFish.update_stale
55
+ end
56
+ end
57
+
58
+ context ".update_stale!" do
59
+ before do
60
+ StaleFish.stub!(:fixtures).and_return([@stale_fixture,@fresh_fixture])
61
+ @stale_fixture.stub!(:update!).and_return(true)
62
+ @fresh_fixture.stub!(:update!).and_return(true)
63
+ StaleFish.should_receive(:write)
64
+ end
65
+
66
+ it "should only call update! on all fixtures" do
67
+ @stale_fixture.should_receive(:update!).once
68
+ @fresh_fixture.should_receive(:update!).once
69
+ StaleFish.update_stale!
70
+ end
71
+
72
+ it "should block requests after completion" do
73
+ StaleFish.should_receive(:allow_requests)
74
+ StaleFish.should_receive(:block_requests)
75
+ StaleFish.update_stale!
76
+ end
77
+ end
78
+
79
+ context ".fixtures" do
80
+ before do
81
+ StaleFish.fixtures.size.should == 2
82
+ end
83
+
84
+ it "should accept the :all parameter" do
85
+ StaleFish.fixtures(:all).size == 2
86
+ end
87
+
88
+ it "should accept the :only parameter with an array of symbols" do
89
+ response = StaleFish.fixtures(:only => [:twitter])
90
+ response.size.should == 1
91
+ response.first.name.should == 'twitter'
92
+ end
93
+
94
+ it "should accept the :except parameter with an array of symbols" do
95
+ response = StaleFish.fixtures(:except => [:twitter])
96
+ response.size.should == 1
97
+ response.first.name.should_not == 'twitter'
98
+ end
99
+
100
+ end
101
+
102
+ context ".write" do
103
+ before do
104
+ StaleFish.stub!(:fixtures).and_return([@stale_fixture,@fresh_fixture])
105
+ File.should_receive(:open).and_return(true)
106
+ end
107
+
108
+ it "should overwrite the contents of the YAML file" do
109
+ StaleFish.send(:write)
110
+ end
111
+ end
112
+
113
+ context ".allow_requests" do
114
+ it "should disable FakeWeb" do
115
+ StaleFish.send(:allow_requests).should == true
116
+ end
117
+ end
118
+
119
+ context ".block_requests" do
120
+ it "should disable FakeWeb" do
121
+ StaleFish.send(:block_requests).should == false
122
+ end
123
+ end
124
+ end
data/stale_fish.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{stale_fish}
8
- s.version = "1.2.4"
8
+ s.version = "1.3.0.pre"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Justin Smestad"]
12
- s.date = %q{2009-10-03}
12
+ s.date = %q{2010-02-22}
13
13
  s.email = %q{justin.smestad@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -17,25 +17,26 @@ Gem::Specification.new do |s|
17
17
  ]
18
18
  s.files = [
19
19
  ".gitignore",
20
+ "Gemfile",
20
21
  "LICENSE",
21
22
  "README.rdoc",
22
23
  "Rakefile",
23
24
  "VERSION",
24
25
  "lib/stale_fish.rb",
25
- "lib/stale_fish/fakeweb.rb",
26
- "lib/stale_fish/fixture_definition.rb",
27
- "lib/stale_fish/utility.rb",
28
- "spec/deprecation_spec.rb",
26
+ "lib/stale_fish/fixture.rb",
29
27
  "spec/fixtures/deprecated_yaml.yml",
30
28
  "spec/fixtures/google.html",
31
29
  "spec/fixtures/malformed_stale_fish.yml",
32
30
  "spec/fixtures/stale_fish.yml",
33
31
  "spec/fixtures/stale_fish_fakeweb.yml",
34
32
  "spec/fixtures/yahoo.html",
33
+ "spec/spec.opts",
35
34
  "spec/spec_helper.rb",
36
- "spec/stale_fish_spec.rb",
37
- "stale_fish.gemspec",
38
- "tmp/.gitignore"
35
+ "spec/support/stale_fish.yml",
36
+ "spec/support/test.yml",
37
+ "spec/unit/fixture_spec.rb",
38
+ "spec/unit/stale_fish_spec.rb",
39
+ "stale_fish.gemspec"
39
40
  ]
40
41
  s.homepage = %q{http://github.com/jsmestad/stale_fish}
41
42
  s.rdoc_options = ["--charset=UTF-8"]
@@ -43,9 +44,9 @@ Gem::Specification.new do |s|
43
44
  s.rubygems_version = %q{1.3.5}
44
45
  s.summary = %q{keeps fixtures synchronized with sources to prevent outdated fixtures going undetected.}
45
46
  s.test_files = [
46
- "spec/deprecation_spec.rb",
47
- "spec/spec_helper.rb",
48
- "spec/stale_fish_spec.rb"
47
+ "spec/spec_helper.rb",
48
+ "spec/unit/fixture_spec.rb",
49
+ "spec/unit/stale_fish_spec.rb"
49
50
  ]
50
51
 
51
52
  if s.respond_to? :specification_version then
@@ -53,20 +54,15 @@ Gem::Specification.new do |s|
53
54
  s.specification_version = 3
54
55
 
55
56
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
- s.add_runtime_dependency(%q<facets>, [">= 0"])
57
- s.add_runtime_dependency(%q<fakeweb>, [">= 1.2.4"])
58
- s.add_runtime_dependency(%q<resourceful>, ["~> 0.6.1"])
59
- s.add_runtime_dependency(%q<activesupport>, [">= 2.1.2"])
57
+ s.add_runtime_dependency(%q<fakeweb>, [">= 0"])
58
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
60
59
  else
61
- s.add_dependency(%q<facets>, [">= 0"])
62
- s.add_dependency(%q<fakeweb>, [">= 1.2.4"])
63
- s.add_dependency(%q<resourceful>, ["~> 0.6.1"])
64
- s.add_dependency(%q<activesupport>, [">= 2.1.2"])
60
+ s.add_dependency(%q<fakeweb>, [">= 0"])
61
+ s.add_dependency(%q<activesupport>, [">= 0"])
65
62
  end
66
63
  else
67
- s.add_dependency(%q<facets>, [">= 0"])
68
- s.add_dependency(%q<fakeweb>, [">= 1.2.4"])
69
- s.add_dependency(%q<resourceful>, ["~> 0.6.1"])
70
- s.add_dependency(%q<activesupport>, [">= 2.1.2"])
64
+ s.add_dependency(%q<fakeweb>, [">= 0"])
65
+ s.add_dependency(%q<activesupport>, [">= 0"])
71
66
  end
72
67
  end
68
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stale_fish
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.3.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Smestad
@@ -9,19 +9,9 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-03 00:00:00 -06:00
12
+ date: 2010-02-22 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: facets
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
25
15
  - !ruby/object:Gem::Dependency
26
16
  name: fakeweb
27
17
  type: :runtime
@@ -30,17 +20,7 @@ dependencies:
30
20
  requirements:
31
21
  - - ">="
32
22
  - !ruby/object:Gem::Version
33
- version: 1.2.4
34
- version:
35
- - !ruby/object:Gem::Dependency
36
- name: resourceful
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ~>
42
- - !ruby/object:Gem::Version
43
- version: 0.6.1
23
+ version: "0"
44
24
  version:
45
25
  - !ruby/object:Gem::Dependency
46
26
  name: activesupport
@@ -50,7 +30,7 @@ dependencies:
50
30
  requirements:
51
31
  - - ">="
52
32
  - !ruby/object:Gem::Version
53
- version: 2.1.2
33
+ version: "0"
54
34
  version:
55
35
  description:
56
36
  email: justin.smestad@gmail.com
@@ -63,25 +43,26 @@ extra_rdoc_files:
63
43
  - README.rdoc
64
44
  files:
65
45
  - .gitignore
46
+ - Gemfile
66
47
  - LICENSE
67
48
  - README.rdoc
68
49
  - Rakefile
69
50
  - VERSION
70
51
  - lib/stale_fish.rb
71
- - lib/stale_fish/fakeweb.rb
72
- - lib/stale_fish/fixture_definition.rb
73
- - lib/stale_fish/utility.rb
74
- - spec/deprecation_spec.rb
52
+ - lib/stale_fish/fixture.rb
75
53
  - spec/fixtures/deprecated_yaml.yml
76
54
  - spec/fixtures/google.html
77
55
  - spec/fixtures/malformed_stale_fish.yml
78
56
  - spec/fixtures/stale_fish.yml
79
57
  - spec/fixtures/stale_fish_fakeweb.yml
80
58
  - spec/fixtures/yahoo.html
59
+ - spec/spec.opts
81
60
  - spec/spec_helper.rb
82
- - spec/stale_fish_spec.rb
61
+ - spec/support/stale_fish.yml
62
+ - spec/support/test.yml
63
+ - spec/unit/fixture_spec.rb
64
+ - spec/unit/stale_fish_spec.rb
83
65
  - stale_fish.gemspec
84
- - tmp/.gitignore
85
66
  has_rdoc: true
86
67
  homepage: http://github.com/jsmestad/stale_fish
87
68
  licenses: []
@@ -99,9 +80,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
80
  version:
100
81
  required_rubygems_version: !ruby/object:Gem::Requirement
101
82
  requirements:
102
- - - ">="
83
+ - - ">"
103
84
  - !ruby/object:Gem::Version
104
- version: "0"
85
+ version: 1.3.1
105
86
  version:
106
87
  requirements: []
107
88
 
@@ -111,6 +92,6 @@ signing_key:
111
92
  specification_version: 3
112
93
  summary: keeps fixtures synchronized with sources to prevent outdated fixtures going undetected.
113
94
  test_files:
114
- - spec/deprecation_spec.rb
115
95
  - spec/spec_helper.rb
116
- - spec/stale_fish_spec.rb
96
+ - spec/unit/fixture_spec.rb
97
+ - spec/unit/stale_fish_spec.rb
@@ -1,26 +0,0 @@
1
- module StaleFish
2
-
3
- class << self
4
- attr_accessor :use_fakeweb
5
- end
6
-
7
- self.use_fakeweb = true
8
-
9
- class FixtureDefinition
10
- alias_method :update_without_fakeweb, :update!
11
-
12
- def update!
13
- FakeWeb.allow_net_connect = true
14
- update_without_fakeweb
15
- FakeWeb.allow_net_connect = false
16
- end
17
-
18
- def register_uri
19
- if StaleFish.use_fakeweb && !FakeWeb.registered_uri?(:any, source_url)
20
- FakeWeb.register_uri(:any, source_url, :body => file_path)
21
- end
22
- end
23
-
24
- end
25
-
26
- end
@@ -1,34 +0,0 @@
1
- module StaleFish
2
-
3
- class FixtureDefinition
4
- attr_accessor :tag, :file_path, :source_url, :last_updated_at, :response
5
- attr_accessor :update_frequency
6
-
7
- def is_stale?
8
- StaleFish.force_flag || last_updated_at.nil? || ((DateTime.now + eval(update_frequency)) < last_updated_at)
9
- end
10
-
11
- def update!
12
- begin
13
- self.response = StaleFish.http.resource(source_url).get
14
- File.open(eval(file_path), 'w') { |file| file.write(response.body.to_s) }
15
- self.last_updated_at = DateTime.now
16
- rescue Resourceful::UnsuccessfulHttpRequestError
17
- raise StaleFish::FixtureUpdateFailure, "#{key}'s source: #{value['source']} returned unsuccessfully."
18
- rescue ArgumentError
19
- raise StaleFish::MalformedSourceURL, "#{key}'s source: #{value['source']} is not a valid URL path. Most likely it's missing a trailing slash."
20
- end
21
- end
22
-
23
- def output_hash
24
- <<-EOF
25
- #{tag}:
26
- file_path: #{file_path}
27
- source_url: #{source_url}
28
- update_frequency: #{update_frequency}
29
- last_updated_at: #{last_updated_at}
30
- EOF
31
- end
32
- end
33
-
34
- end
@@ -1,67 +0,0 @@
1
- require 'singleton'
2
-
3
- module StaleFish
4
- module Utility
5
- class << self
6
- attr_accessor :config_path
7
- end
8
-
9
- def self.valid_path?
10
- !config_path.nil? ? File.exist?(config_path) : false
11
- end
12
-
13
- def self.loader
14
- raise Errno::ENOENT, 'invalid config path: #{Utility.config_path}; ensure StaleFish::Utility.valid_path? is true' unless Utility.valid_path?
15
-
16
- data = YAML.load_file(config_path)
17
-
18
- config = data['stale'].delete('configuration')
19
- StaleFish.use_fakeweb = (config['use_fakeweb'] || false) unless config.nil?
20
-
21
- raise YAML::Error, 'missing root element' unless data['stale']
22
-
23
- # Reset these
24
- StaleFish.fixtures = []
25
- StaleFish.force_flag = false
26
-
27
- deprecated_var_names = {
28
- 'file_path' => 'filepath',
29
- 'update_frequency' => 'frequency',
30
- 'source_url' => 'source',
31
- 'last_updated_at' => 'updated'
32
- }
33
-
34
- data['stale'].each do |key, value|
35
- definition = FixtureDefinition.new
36
- definition.tag = key
37
- %w{ file_path update_frequency source_url }.each do |field|
38
- if value[deprecated_var_names[field]]
39
- $stderr.puts "Deprecation warning: #{field} has been replaced with #{deprecated_var_names[field]}. Please update #{Utility.config_path}."
40
- definition.send((field + '=').to_sym, value[deprecated_var_names[field]])
41
- else
42
- raise YAML::Error, "missing #{field} node for #{key} in #{Utility.config_path}" unless value[field]
43
- definition.send((field + '=').to_sym, value[field])
44
- end
45
- end
46
-
47
- $stderr.puts "Deprecation warning: updated has been changed to last_updated_at; this change is automatic." if value.has_key?('updated')
48
- definition.last_updated_at = value['last_updated_at'] || value[deprecated_var_names['last_updated_at']] || nil
49
-
50
- StaleFish.fixtures << definition
51
- end
52
- end
53
-
54
- def self.writer
55
- string = <<-EOF
56
- stale:
57
- configuration:
58
- use_fakeweb: #{StaleFish.use_fakeweb}
59
- EOF
60
- StaleFish.fixtures.each do |fix|
61
- string << fix.output_hash
62
- end
63
-
64
- File.open(config_path, "w+") { |f| f.write(string) }
65
- end
66
- end
67
- end
@@ -1,20 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe StaleFish do
4
-
5
- before do
6
- @deprecated_yaml = File.dirname(__FILE__) + "/fixtures/deprecated_yaml.yml"
7
- end
8
-
9
- it "should assign the config file" do
10
- StaleFish::Utility.config_path = @deprecated_yaml
11
- StaleFish::Utility.config_path.should == @deprecated_yaml
12
- StaleFish::Utility.valid_path?.should == true
13
- end
14
-
15
- it "should map to valid attributes" do
16
- pending
17
- StaleFish::Utility.loader
18
- end
19
-
20
- end
@@ -1,104 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "StaleFish" do
4
-
5
- before do
6
- @valid_yaml = File.dirname(__FILE__) + "/fixtures/stale_fish.yml"
7
- end
8
-
9
- it "should assign the config file" do
10
- StaleFish::Utility.config_path = @valid_yaml
11
- StaleFish::Utility.config_path.should == @valid_yaml
12
- StaleFish::Utility.valid_path?.should == true
13
- end
14
-
15
- context "when loading the yaml file" do
16
-
17
- it "should raise errors on malformed yaml" do
18
- StaleFish::Utility.config_path = File.dirname(__FILE__) + "/fixtures/malformed_stale_fish.yml"
19
- lambda { StaleFish::Utility.loader }.should_not raise_error(Errno::ENOENT)
20
- lambda { StaleFish::Utility.loader }.should raise_error(YAML::Error)
21
- end
22
-
23
- it "shouldn't fail on valid yaml" do
24
- StaleFish::Utility.config_path = @valid_yaml
25
- lambda { StaleFish::Utility.loader }.should_not raise_error(YAML::Error)
26
- end
27
-
28
- it "should establish the fixture definitions" do
29
- StaleFish::Utility.config_path = @valid_yaml
30
- lambda { StaleFish::Utility.loader }
31
- end
32
-
33
- end
34
-
35
- context "after loading the config" do
36
-
37
- before(:each) do
38
- FileUtils.cp(@valid_yaml, File.dirname(__FILE__) + "/fixtures/stale_fish.orig.yml")
39
- StaleFish::Utility.config_path = @valid_yaml
40
- StaleFish::Utility.valid_path?.should == true
41
- StaleFish::Utility.loader
42
- end
43
-
44
- it "should update all stale fixtures" do
45
- StaleFish.update_stale.should == 2
46
- end
47
-
48
- it "should update only the passed fixtures, if stale" do
49
- StaleFish.update_stale('google').should == 1
50
- end
51
-
52
- it "should update all passed fixtures, when passed the :force flag" do
53
- StaleFish.update_stale('google').should == 1
54
- StaleFish.update_stale('google', :force => true).should == 1
55
- end
56
-
57
- it "should not have any remaining fixtures to update" do
58
- StaleFish.update_stale.should == 2
59
- StaleFish.fixtures = [] # this will force a reload of the YAML file.
60
- StaleFish.fixtures.should == [] # ensure it was reset
61
- StaleFish::Utility.loader
62
- StaleFish.update_stale.should == 0
63
- end
64
-
65
- it "should notify user, and rollback, if source is no longer valid"
66
-
67
- after(:each) do
68
- FileUtils.mv(@valid_yaml, File.dirname(__FILE__)+"/../tmp/stale_fish.test.yml")
69
- FileUtils.mv(File.dirname(__FILE__)+"/fixtures/stale_fish.orig.yml", @valid_yaml)
70
- StaleFish.fixtures = []
71
- end
72
-
73
- end
74
-
75
- context "with FakeWeb" do
76
-
77
- before(:each) do
78
- @fakeweb_yaml = File.dirname(__FILE__) + '/fixtures/stale_fish_fakeweb.yml'
79
- StaleFish::Utility.config_path = @fakeweb_yaml
80
- StaleFish::Utility.valid_path?.should == true
81
- StaleFish::Utility.loader
82
- StaleFish.use_fakeweb = true
83
- StaleFish.use_fakeweb.should == true
84
- end
85
-
86
- it "should register any FakeWeb URI's" do
87
- definition = StaleFish.fixtures.first
88
- definition.register_uri
89
- FakeWeb.registered_uri?(definition.source_url).should == true
90
- end
91
-
92
- it "should turn off FakeWeb.allow_net_connect to process stale fixtures" do
93
- FakeWeb.allow_net_connect = false
94
- lambda { StaleFish.update_stale(:force => true) }.should_not raise_error
95
- lambda { StaleFish.update_stale(:force => true) }.should_not change { FakeWeb.allow_net_connect? }
96
- end
97
-
98
- after(:each) do
99
- StaleFish.fixtures = []
100
- end
101
-
102
- end
103
-
104
- end