stale_fish 1.3.0.pre → 1.3.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,42 +1,41 @@
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. StaleFish also allows for FakeWeb integration and URI management.
3
+ StaleFish is a utility for storing web requests as fixtures, faking web requests, and ensuring fixtures stay fresh by checking request at periodic intervals.
4
+ It works at a global level, without modifying code or writing extensive stubs.
4
5
 
5
6
  == NOTICE
6
7
 
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.
8
+ 1.3.x is a complete rewrite of the StaleFish utility. It is incompatible with previous versions of StaleFish.
10
9
 
11
10
  == Features
12
11
 
13
- * Fixture update frequency uses the ActiveSupport relative time DSL
14
- * Versioned configuration file & fixtures means fixtures are only updated once per project.
15
- * Manage FakeWeb stubbed URI's through StaleFish
16
- * Automatic detection for Rails & Rack apps (default configuration locations)
12
+ * Manage FakeWeb through StaleFish
13
+ * Fixtures are updated based on a per-fixture update interval
14
+ * Fixture update interval supports the ActiveSupport relative time DSL (ex. '30.minutes', '2.days', '1.year')
15
+ * Configuration file and fixture data is version control friendly
16
+ * Specify which fixtures are checked for freshness using :all, :only, & :except arguement options
17
+ * Force update of all fixtures regardless of freshness (bypass freshness check)
17
18
  * Test Framework agnostic (tested with Test::Unit & RSpec)
18
- * Update all fixtures, specified fixtures, or forced update are all supported through the StaleFish.update_stale(*args) method
19
- * 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.
20
19
 
21
20
  == How To
22
21
 
23
- Simply drop in a YAML file in your application (default location: {test/spec}/stale_fish.yml; overwrite by setting StaleFish::Utility.config_path) and issue the following commands.
22
+ Simply drop in a YAML file in your application (recommended location: {test/spec}/fixtures/stale_fish.yml) and issue the following commands.
24
23
 
25
24
  A sample YAML file:
26
25
 
27
26
  stale:
28
- configuration:
29
- use_fakeweb: true
30
- yahoo:
31
- file_path: RAILS_ROOT + '/spec/fixtures/yahoo.html'
32
- source_url: http://www.yahoo.com
33
- last_updated_at:
34
- update_frequency: 1.day
35
- google:
36
- file_path: RAILS_ROOT + '/spec/fixtures/github_commit.json'
37
- source_url: http://api.github.com/post_commit/
38
- last_updated_at:
39
- update_frequency: 2.weeks
27
+ twitter: # fixture name (this must be unique)
28
+ file: 'timeline.json' # fixture save location
29
+ update_interval: 30.days # update interval
30
+ check_against: http://twitter.com/api/timeline # data to update fixture with when stale
31
+ request_type: POST # request type to use when updating: GET, POST
32
+ last_updated_at: # timestamp of last fixture update (can be left blank)
33
+ gh_commits:
34
+ file: 'commits.xml'
35
+ update_interval: 3.days
36
+ check_against: http://api.github.com/commits.xml
37
+ request_type: GET
38
+ last_updated_at:
40
39
 
41
40
  Specify one block for every fixture you would like to update. The frequency field takes any relative date included in the ActiveSupport library.
42
41
 
@@ -46,7 +45,7 @@ For a single test add it to a before block
46
45
 
47
46
  describe UsersController do
48
47
  before do
49
- StaleFish.update_stale("facebook", "yahoo")
48
+ StaleFish.update_stale
50
49
  end
51
50
  ....
52
51
  end
@@ -57,7 +56,7 @@ For all tests add the following to spec_helper.rb
57
56
 
58
57
  Spec::Runner.configure do |config|
59
58
  ...
60
- config.before do
59
+ config.before :suite do
61
60
  StaleFish.update_stale
62
61
  end
63
62
  ....
@@ -68,9 +67,6 @@ For all tests add the following to spec_helper.rb
68
67
  For all tests add the following to test_helper.rb
69
68
 
70
69
  class Test::Unit::TestCase
71
- ...
72
- self.use_transactional_fixtures = true
73
- self.use_instantiated_fixtures = false
74
70
  ...
75
71
  setup do
76
72
  StaleFish.update_stale
@@ -78,14 +74,15 @@ For all tests add the following to test_helper.rb
78
74
  ...
79
75
  end
80
76
 
77
+
81
78
  == More Info
82
79
 
83
80
  View the wiki: http://wiki.github.com/jsmestad/stale_fish
84
81
 
85
82
  == Thanks
86
83
 
87
- Paul Sadauskas for his work on Resourceful (used by StaleFish to provide accurate http handling when updating fixtures)
84
+ This utility uses FakeWeb, thanks to those contributors for there excellent work.
88
85
 
89
86
  == Copyright
90
87
 
91
- Copyright (c) 2009 Justin Smestad. See LICENSE for details.
88
+ Copyright (c) 2009-2010 Justin Smestad. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0.pre
1
+ 1.3.0.pre1
@@ -10,7 +10,7 @@ module StaleFish
10
10
  end
11
11
 
12
12
  def is_stale?
13
- if (last_updated_at + update_interval) < Time.now
13
+ if last_updated_at.nil? || (last_updated_at + update_interval) < Time.now
14
14
  return true
15
15
  else
16
16
  return false
@@ -19,14 +19,14 @@ module StaleFish
19
19
 
20
20
  def update!
21
21
  uri, type = URI.parse(check_against), request_type.downcase.to_sym
22
- Net::HTTP.start(uri.host) { |http|
22
+ Net::HTTP.start(uri.host) do |http|
23
23
  response = if type == :post
24
- http.post(uri.path, uri.query)
25
- else
26
- http.get(uri.path)
27
- end
24
+ http.post(uri.path)
25
+ else
26
+ http.get(uri.path)
27
+ end
28
28
  write_response_to_file(response.body)
29
- }
29
+ end
30
30
 
31
31
  self.last_updated_at = Time.now
32
32
  end
data/lib/stale_fish.rb CHANGED
@@ -9,6 +9,13 @@ module StaleFish
9
9
  # no one likes stale fish.
10
10
  class << self
11
11
 
12
+ def setup(config_location=nil)
13
+ self.configuration = config_location
14
+ load
15
+ register_fixtures
16
+ block_requests
17
+ end
18
+
12
19
  def configuration=(config)
13
20
  @configuration = config
14
21
  end
@@ -22,12 +29,16 @@ module StaleFish
22
29
  end
23
30
 
24
31
  def update_stale(options={})
32
+ reset_fixtures = false
33
+
25
34
  allow_requests
26
35
  fixtures(options).each do |fixture|
27
36
  if fixture.is_stale?
28
37
  fixture.update!
38
+ reset_fixtures = true
29
39
  end
30
40
  end
41
+ register_fixtures if reset_fixtures
31
42
  block_requests
32
43
  write
33
44
  end
@@ -37,6 +48,7 @@ module StaleFish
37
48
  fixtures(options).each do |fixture|
38
49
  fixture.update!
39
50
  end
51
+ register_fixtures
40
52
  block_requests
41
53
  write
42
54
  end
@@ -81,5 +93,12 @@ module StaleFish
81
93
  def block_requests
82
94
  FakeWeb.allow_net_connect = false
83
95
  end
96
+
97
+ def register_fixtures
98
+ FakeWeb.clean_registry
99
+ fixtures.each do |fixture|
100
+ fixture.register_lock!
101
+ end
102
+ end
84
103
  end
85
104
  end
@@ -37,6 +37,11 @@ describe StaleFish::Fixture do
37
37
  it "should return false when fresh" do
38
38
  @fresh_fixture.is_stale?.should == false
39
39
  end
40
+
41
+ it "should return true when last_updated_at is empty" do
42
+ @stale_fixture.last_updated_at = nil
43
+ @stale_fixture.is_stale?.should == true
44
+ end
40
45
  end
41
46
 
42
47
  context "#update!" do
@@ -3,9 +3,22 @@ require File.join(File.dirname(__FILE__), *%w[.. spec_helper])
3
3
  describe StaleFish do
4
4
  before do
5
5
  @stale_fixture = StaleFish::Fixture.new(:last_updated_at => 1.week.ago,
6
- :update_interval => 1.day)
6
+ :update_interval => 1.day,
7
+ :request_type => 'GET',
8
+ :check_against => 'http://google.com/index.html')
7
9
  @fresh_fixture = StaleFish::Fixture.new(:last_updated_at => 1.day.from_now,
8
- :update_interval => 1.day)
10
+ :update_interval => 1.day,
11
+ :request_type => 'GET',
12
+ :check_against => 'http://google.com/index.html')
13
+ end
14
+
15
+ context ".setup" do
16
+ it "should call appropriate functions" do
17
+ StaleFish.should_receive(:load)
18
+ StaleFish.should_receive(:register_fixtures)
19
+ StaleFish.should_receive(:block_requests)
20
+ StaleFish.setup
21
+ end
9
22
  end
10
23
 
11
24
  context ".configuration" do
@@ -121,4 +134,8 @@ describe StaleFish do
121
134
  StaleFish.send(:block_requests).should == false
122
135
  end
123
136
  end
137
+
138
+ context ".register_fixtures" do
139
+
140
+ end
124
141
  end
data/stale_fish.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{stale_fish}
8
- s.version = "1.3.0.pre"
8
+ s.version = "1.3.0.pre1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Justin Smestad"]
@@ -24,12 +24,6 @@ Gem::Specification.new do |s|
24
24
  "VERSION",
25
25
  "lib/stale_fish.rb",
26
26
  "lib/stale_fish/fixture.rb",
27
- "spec/fixtures/deprecated_yaml.yml",
28
- "spec/fixtures/google.html",
29
- "spec/fixtures/malformed_stale_fish.yml",
30
- "spec/fixtures/stale_fish.yml",
31
- "spec/fixtures/stale_fish_fakeweb.yml",
32
- "spec/fixtures/yahoo.html",
33
27
  "spec/spec.opts",
34
28
  "spec/spec_helper.rb",
35
29
  "spec/support/stale_fish.yml",
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.3.0.pre
4
+ version: 1.3.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Smestad
@@ -50,12 +50,6 @@ files:
50
50
  - VERSION
51
51
  - lib/stale_fish.rb
52
52
  - lib/stale_fish/fixture.rb
53
- - spec/fixtures/deprecated_yaml.yml
54
- - spec/fixtures/google.html
55
- - spec/fixtures/malformed_stale_fish.yml
56
- - spec/fixtures/stale_fish.yml
57
- - spec/fixtures/stale_fish_fakeweb.yml
58
- - spec/fixtures/yahoo.html
59
53
  - spec/spec.opts
60
54
  - spec/spec_helper.rb
61
55
  - spec/support/stale_fish.yml
@@ -1,12 +0,0 @@
1
- ---
2
- stale:
3
- yahoo:
4
- filepath: ./tmp/yahoo.html
5
- source: http://www.yahoo.com/
6
- updated:
7
- frequency: 1.day
8
- google:
9
- filepath: ./tmp/google.html
10
- source: http://www.google.com/
11
- updated:
12
- frequency: 2.weeks
File without changes
@@ -1,5 +0,0 @@
1
- stale:
2
- google:
3
- file_path: google.html
4
- yahoo:
5
- update_frequency: 2.weeks.ago
@@ -1,11 +0,0 @@
1
- stale:
2
- yahoo:
3
- file_path: ./tmp/yahoo.html
4
- source_url: http://www.yahoo.com/
5
- last_updated_at:
6
- update_frequency: 1.day
7
- google:
8
- file_path: ./tmp/google.html
9
- source_url: http://www.google.com/
10
- last_updated_at:
11
- update_frequency: 2.weeks
@@ -1,13 +0,0 @@
1
- stale:
2
- configuration:
3
- use_fakeweb: true
4
- yahoo:
5
- file_path: ./tmp/yahoo.html
6
- source_url: http://www.yahoo.com/
7
- update_frequency: 1.day
8
- last_updated_at: 2009-11-30T18:26:20-07:00
9
- google:
10
- file_path: ./tmp/google.html
11
- source_url: http://www.google.com/
12
- update_frequency: 2.weeks
13
- last_updated_at: 2009-11-30T18:26:20-07:00
File without changes