edboxra 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/.autotest +8 -0
  2. data/.gitignore +3 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +36 -0
  6. data/LICENSE +20 -0
  7. data/README +2 -0
  8. data/Rakefile +19 -0
  9. data/edboxra.gemspec +30 -0
  10. data/lib/edboxra.rb +14 -0
  11. data/lib/edboxra/api.rb +26 -0
  12. data/lib/edboxra/api_factory.rb +28 -0
  13. data/lib/edboxra/movie.rb +9 -0
  14. data/lib/edboxra/v1/v1_api.rb +63 -0
  15. data/lib/edboxra/v2/v2_api.rb +67 -0
  16. data/lib/edboxra/version.rb +4 -0
  17. data/showoff/bdd/01_we_love_bdd.md +6 -0
  18. data/showoff/bdd/02_structure.md +17 -0
  19. data/showoff/bdd/03_expectations.md +20 -0
  20. data/showoff/closing/01_closing.md +5 -0
  21. data/showoff/custom.css +4 -0
  22. data/showoff/history/01_history.md +9 -0
  23. data/showoff/intro/01_write_your_own.md +6 -0
  24. data/showoff/intro/02_in_the_box.md +10 -0
  25. data/showoff/mocking/01_got_mock.md +3 -0
  26. data/showoff/mocking/02_simple.md +10 -0
  27. data/showoff/mocking/03_example.md +24 -0
  28. data/showoff/other/01_other.md +3 -0
  29. data/showoff/other/02_randomization.md +40 -0
  30. data/showoff/other/FIRST.jpg +0 -0
  31. data/showoff/performance/01_build_right_in.md +5 -0
  32. data/showoff/performance/02_add_to_tests.md +9 -0
  33. data/showoff/performance/03_example.md +21 -0
  34. data/showoff/performance/04_assertions.md +12 -0
  35. data/showoff/showoff.json +13 -0
  36. data/showoff/tdd/01_structure.md +20 -0
  37. data/showoff/tdd/02_run_it.md +17 -0
  38. data/showoff/tdd/03_assertions.md +23 -0
  39. data/showoff/tdd/04_skip_pass_flunk.md +24 -0
  40. data/showoff/tdd/05_capture_io.md +22 -0
  41. data/showoff/testunit/01_whats_wrong.md +8 -0
  42. data/showoff/title/01_title.md +5 -0
  43. data/test/integration/test_edboxra.rb +18 -0
  44. data/test/unit/helpers/fake_box.rb +53 -0
  45. data/test/unit/helpers/log_stub.rb +4 -0
  46. data/test/unit/helpers/test_helper.rb +8 -0
  47. data/test/unit/test_api_factory.rb +32 -0
  48. data/test/unit/v1/test_v1_api.rb +61 -0
  49. data/test/unit/v2/test_v2_api.rb +54 -0
  50. metadata +193 -0
@@ -0,0 +1,8 @@
1
+ require 'autotest/growl'
2
+ require 'autotest/fsevent'
3
+
4
+ Autotest.add_hook :initialize do |at|
5
+ at.testlib = 'minitest/unit'
6
+ at.libs = %w[. lib test/unit test/unit/helpers].join(File::PATH_SEPARATOR)
7
+ at.add_exception 'integration'
8
+ end
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ .bundle
3
+ vendor/ruby
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ edboxra (0.0.1)
5
+ json (~> 1.5)
6
+ rest-client (~> 1.6)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ ZenTest (4.4.2)
12
+ addressable (2.2.4)
13
+ autotest-fsevent (0.2.4)
14
+ sys-uname
15
+ autotest-growl (0.2.9)
16
+ crack (0.1.8)
17
+ json (1.5.1)
18
+ mime-types (1.16)
19
+ minitest (2.0.2)
20
+ rest-client (1.6.1)
21
+ mime-types (>= 1.16)
22
+ sys-uname (0.8.5)
23
+ webmock (1.6.2)
24
+ addressable (>= 2.2.2)
25
+ crack (>= 0.1.7)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ ZenTest (~> 4.4)
32
+ autotest-fsevent (~> 0.2)
33
+ autotest-growl (~> 0.2)
34
+ edboxra!
35
+ minitest (~> 2.0)
36
+ webmock (~> 1.6)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Darrin Holst
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,2 @@
1
+ A utility for interacting with some movie box place...
2
+
@@ -0,0 +1,19 @@
1
+ require 'bundler'
2
+ require 'rake/testtask'
3
+
4
+ Bundler.require(:default)
5
+ Bundler::GemHelper.install_tasks
6
+
7
+ Rake::TestTask.new do |task|
8
+ task.libs << 'test/unit'
9
+ task.libs << 'test/unit/helpers'
10
+ task.test_files = FileList['test/unit/**/test*.rb']
11
+ end
12
+
13
+ Rake::TestTask.new('test:integration') do |task|
14
+ task.libs << 'test/integration'
15
+ task.test_files = FileList['test/integration/**/test*.rb']
16
+ end
17
+
18
+ task :default => :test
19
+
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'edboxra/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "edboxra"
7
+ s.version = Edboxra::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Darrin Holst"]
10
+ s.email = ["darrinholst@gmail.com"]
11
+ s.homepage = "http://github.com/darrinholst/edboxra"
12
+ s.summary = "Interface to some movie box place"
13
+ s.description = "Interface to some movie box place"
14
+
15
+ s.rubyforge_project = "edboxra"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "rest-client", "~> 1.6"
23
+ s.add_dependency "json", "~> 1.5"
24
+ s.add_development_dependency "webmock", "~> 1.6"
25
+ s.add_development_dependency "minitest", "~> 2.0"
26
+ s.add_development_dependency "ZenTest", "~> 4.4"
27
+ s.add_development_dependency "autotest-growl", "~> 0.2"
28
+ s.add_development_dependency "autotest-fsevent", "~> 0.2"
29
+ end
30
+
@@ -0,0 +1,14 @@
1
+ require 'edboxra/version'
2
+ require 'edboxra/api_factory'
3
+ require 'edboxra/api'
4
+ require 'edboxra/movie'
5
+ require 'edboxra/v1/v1_api'
6
+ require 'edboxra/v2/v2_api'
7
+
8
+ module Net::HTTPHeader
9
+ def capitalize(name)
10
+ return "__K" if name.eql? "__k"
11
+ name.split(/-/).map {|s| s.capitalize }.join('-')
12
+ end
13
+ end
14
+
@@ -0,0 +1,26 @@
1
+ module Edboxra
2
+ class Api
3
+ def initialize(key, cookies)
4
+ @key = key
5
+ @cookies = parse_cookies(cookies)
6
+ end
7
+
8
+ private
9
+
10
+ def parse_cookies(cookies)
11
+ out = {}
12
+
13
+ [cookies].flatten.each do |raw_cookie|
14
+ raw_cookie.split(";").each do |cookie_part|
15
+ key, val = cookie_part.strip.split("=", 2)
16
+
17
+ unless %w(expires domain path secure HttpOnly).member?(key)
18
+ out[key] = val
19
+ end
20
+ end
21
+ end
22
+
23
+ out
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ require 'restclient'
2
+ require 'logger'
3
+
4
+ module Edboxra
5
+ class ApiFactory
6
+ def initialize(logger = nil)
7
+ @log = logger || Logger.new(STDOUT)
8
+ end
9
+
10
+ def create_api
11
+ response = RestClient.get("http://www.redbox.com")
12
+
13
+ try_version(V1::Api, response) ||
14
+ try_version(V2::Api, response)
15
+ end
16
+
17
+ private
18
+
19
+ def try_version(version, response)
20
+ match = version::KEY_REGEX.match(response.body)
21
+
22
+ if(match)
23
+ @log.debug("found api key -- #{match[1]}")
24
+ version.new(match[1], response.headers[:set_cookie]) if match
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,9 @@
1
+ class Edboxra::Movie
2
+ attr_accessor :id, :name, :release_date, :image,
3
+ :genre_ids, :blu_ray, :description,
4
+ :rating, :running_time, :actors, :genre
5
+
6
+ def blu_ray?
7
+ blu_ray == true
8
+ end
9
+ end
@@ -0,0 +1,63 @@
1
+ require 'json'
2
+ require 'date'
3
+
4
+ module Edboxra
5
+ module V1
6
+ class Api < Edboxra::Api
7
+ KEY_REGEX = /__K.*value="(.*)"/
8
+
9
+ def get_movies
10
+ resp = RestClient.get("http://www.redbox.com/data.svc/Title/js")
11
+
12
+ match = /=\ *(\[.*\]);/.match(resp.body)
13
+ raise "couldn't find movies in #{resp.body}" unless match
14
+
15
+ json = JSON.parse(match[1])
16
+ json.map{|movie| map_movie(movie)}
17
+ end
18
+
19
+ def add_metadata_to(movie)
20
+ postData = JSON.generate({
21
+ :type => "Title",
22
+ :pk => "ID",
23
+ :statements => [{:filters => {:ID => movie.id}}],
24
+ "__K" => @key
25
+ })
26
+
27
+ response = RestClient.post("http://www.redbox.com/data.svc/Title", postData, post_headers)
28
+ map_metadata(movie, JSON.parse(response_object_from(response.body)))
29
+ end
30
+
31
+ private
32
+
33
+ def post_headers
34
+ {'Cookie' => @cookies.map{|k,v| "#{k}=#{v}"}.join("; ")}
35
+ end
36
+
37
+ def response_object_from(json)
38
+ match = /\{.*?\:(.*)\}/.match(json)
39
+ raise "couldn't find response object in #{json}" unless match
40
+ match[1] if match
41
+ end
42
+
43
+ def map_movie(json)
44
+ movie = Movie.new
45
+ movie.id = json["ID"]
46
+ movie.name = json["Name"]
47
+ movie.release_date = Date.parse(json['Release'])
48
+ movie.image = json["Img"]
49
+ movie.genre_ids = json["GenreIDs"]
50
+ movie.blu_ray = json["FormatID"].eql? "2"
51
+ movie
52
+ end
53
+
54
+ def map_metadata(movie, json)
55
+ movie.description = json["Desc"]
56
+ movie.rating = json["Rating"]
57
+ movie.running_time = json["RunningTime"]
58
+ movie.genre = json["Genre"]
59
+ movie.actors = json["Actors"]
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,67 @@
1
+ require 'date'
2
+ require 'json'
3
+
4
+ module Edboxra
5
+ module V2
6
+ class Api < Edboxra::Api
7
+ KEY_REGEX = /rb\.api\.key *= * [',"](.*?)[',"]/
8
+
9
+ def get_movies
10
+ resp = RestClient.get("http://www.redbox.com/api/product/js/__titles")
11
+
12
+ match = /=\ *(\[.*\])/.match(resp.body)
13
+ raise "couldn't find movies in #{resp.body}" unless match
14
+
15
+ json = JSON.parse(match[1])
16
+ json.map{|movie| map_movie(movie)}
17
+ end
18
+
19
+ def add_metadata_to(movie)
20
+ postData = JSON.generate({
21
+ :productType => 1,
22
+ :id => movie.id,
23
+ :descCharLimit => 2000
24
+ })
25
+
26
+ response = RestClient.post("http://www.redbox.com/api/Product/GetDetail/", postData, post_headers)
27
+ map_metadata(movie, JSON.parse(response.body))
28
+ end
29
+
30
+ private
31
+
32
+ def map_movie(json)
33
+ movie = Movie.new
34
+ movie.id = json["ID"]
35
+ movie.name = json["name"]
36
+ movie.release_date = Date.parse(json['release'])
37
+ movie.image = json["img"]
38
+ movie.genre_ids = json["genreIDs"]
39
+ movie.blu_ray = json["fmt"].eql? "2"
40
+ movie
41
+ end
42
+
43
+ def map_metadata(movie, json)
44
+ if(json["d"] && json["d"]["success"] && json["d"]["data"])
45
+ data = json["d"]["data"]
46
+ movie.description = data["desc"]
47
+ movie.rating = data["rating"]
48
+ movie.running_time = data["len"]
49
+ movie.genre = (data["genre"] || []).join(", ")
50
+ movie.actors = (data["starring"] || []).join(", ")
51
+ else
52
+ raise "no metadata - " + resp
53
+ end
54
+ end
55
+
56
+ def post_headers
57
+ {
58
+ "Cookie" => @cookies.map{|k,v| "#{k}=#{v}"}.join("; "),
59
+ "__K" => @key,
60
+ "X-Requested-With" => "XMLHttpRequest",
61
+ "Content-Type" => "application/x-www-form-urlencoded",
62
+ "User-Agent" => "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.231 Safari/534.10",
63
+ }
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,4 @@
1
+ module Edboxra
2
+ VERSION = "0.0.1"
3
+ end
4
+
@@ -0,0 +1,6 @@
1
+ !SLIDE transition=turnDown
2
+
3
+ # BDD #
4
+
5
+ ## Yeah, we have that too (It's just words after all) ##
6
+
@@ -0,0 +1,17 @@
1
+ !SLIDE transition=turnDown
2
+
3
+ # BDD #
4
+
5
+ @@@ruby
6
+ require 'minitest/autorun'
7
+
8
+ describe Post do
9
+ before do
10
+ @post = Post.new("minitest rockz")
11
+ end
12
+
13
+ it "should set the title" do
14
+ @post.title.must_equal "minitest rockz"
15
+ end
16
+ end
17
+
@@ -0,0 +1,20 @@
1
+ !SLIDE small transition=turnDown
2
+
3
+ # BDD #
4
+
5
+ ## expectations ##
6
+
7
+ $ gem install cheat
8
+ $ cheat minitest
9
+
10
+ minitest:
11
+ must_equal -> assert_equal
12
+ must_include -> assert_includes
13
+ must_match -> assert_match
14
+ ...
15
+
16
+ wont_equal -> refute_equal
17
+ wont_include -> refute_includes
18
+ wont_match -> refute_match
19
+ ...
20
+
@@ -0,0 +1,5 @@
1
+ !SLIDE transition=turnDown
2
+
3
+ ## http://github.com/darrinholst/edboxra ##
4
+ ## darrinholst@gmail.com ##
5
+
@@ -0,0 +1,4 @@
1
+ .hl {
2
+ background: yellow;
3
+ }
4
+
@@ -0,0 +1,9 @@
1
+ !SLIDE bullets incremental transition=turnDown
2
+
3
+ # History #
4
+
5
+ * 1999 - RubyUnit
6
+ * 2001 - Lapidary
7
+ * 2001 - test/unit
8
+ * 2006 - minitest
9
+
@@ -0,0 +1,6 @@
1
+ !SLIDE bullets incremental transition=turnDown
2
+
3
+ # What do all programmers do when they don't like something? #
4
+
5
+ * Write your own of course...
6
+
@@ -0,0 +1,10 @@
1
+ !SLIDE bullets incremental transition=turnDown
2
+
3
+ # What's in the box? #
4
+
5
+ * TDD (test/unit compatible api)
6
+ * BDD
7
+ * Mocking (technically true)
8
+ * Benchmarking
9
+ * Plain ol Ruby
10
+
@@ -0,0 +1,3 @@
1
+ !SLIDE transition=turnDown
2
+
3
+ #Got Mock?#
@@ -0,0 +1,10 @@
1
+ !SLIDE bullets incremental transition=turnDown
2
+
3
+ # Mocking #
4
+
5
+ * simple
6
+ * expect
7
+ * verify
8
+ * 61 lines
9
+ * with comments
10
+
@@ -0,0 +1,24 @@
1
+ !SLIDE small transition=turnDown
2
+
3
+ # Mocking #
4
+
5
+ @@@ruby
6
+ require 'minitest/autorun'
7
+ require 'minitest/mock'
8
+
9
+ describe Library do
10
+ before do
11
+ @repo = MiniTest::Mock.new
12
+ @library = Library.new(@repo)
13
+ end
14
+
15
+ it "should find books by name" do
16
+ book = Book.new
17
+ @repo.expect :find, book, ["Minitest In Action"]
18
+
19
+ book_found = @library.find_book "Minitest In Action"
20
+
21
+ book_found.must_be_same_as book
22
+ end
23
+ end
24
+
@@ -0,0 +1,3 @@
1
+ !SLIDE transition=turnDown
2
+
3
+ # Other stuff... #
@@ -0,0 +1,40 @@
1
+ !SLIDE center transition=turnDown
2
+
3
+ # Randomization #
4
+
5
+ ![FIRST](FIRST.jpg)
6
+
7
+ !SLIDE commandline transition=turnDown
8
+
9
+ # Randomization #
10
+
11
+ ## tests are run in a random order ##
12
+
13
+ $ ruby test_post.rb
14
+ Run options: --seed 954
15
+
16
+ # Running tests:
17
+
18
+ .
19
+
20
+ Finished tests in 0.000426s, 2347.4178 tests/s, 2347.4178 assertions/s.
21
+
22
+ 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
23
+
24
+ !SLIDE commandline transition=turnDown
25
+
26
+ # Randomization #
27
+
28
+ ## use --seed option to rerun tests in same order ##
29
+
30
+ $ ruby test_post.rb --seed 954
31
+ Run options: --seed 954
32
+
33
+ # Running tests:
34
+
35
+ .
36
+
37
+ Finished tests in 0.000426s, 2347.4178 tests/s, 2347.4178 assertions/s.
38
+
39
+ 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
40
+
Binary file
@@ -0,0 +1,5 @@
1
+ !SLIDE transition=turnDown
2
+
3
+ # Benchmarking #
4
+
5
+ ## Baked right in ##
@@ -0,0 +1,9 @@
1
+ !SLIDE bullets incremental transition=turnDown
2
+
3
+ # Benchmarking #
4
+
5
+ * methods start with bench_ (even specs)
6
+ * add them right to unit tests
7
+ * won't run if unit tests fail
8
+ * conditionally require benchmark
9
+
@@ -0,0 +1,21 @@
1
+ !SLIDE small transition=turnDown
2
+
3
+ # Benchmarking #
4
+
5
+ @@@ruby
6
+ require 'minitest/benchmark' if ENV["BENCH"]
7
+ require 'minitest/autorun'
8
+
9
+ class TestSecretStuff < MiniTest::Unit::TestCase
10
+ # Override self.bench_range
11
+ # default range is [1, 10, 100, 1_000, 10_000]
12
+
13
+ def bench_my_algorithm
14
+ assert_performance_linear 0.9999 do |n|
15
+ n.times do
16
+ @obj.my_algorithm
17
+ end
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,12 @@
1
+ !SLIDE small bullets transition=turnDown
2
+
3
+ # Benchmarking #
4
+
5
+ ## assertions ##
6
+
7
+ * assert\_performance\_constant
8
+ * assert\_performance\_exponential
9
+ * assert\_performance\_linear
10
+ * assert\_performance\_power
11
+
12
+
@@ -0,0 +1,13 @@
1
+ [
2
+ {"section":"title"},
3
+ {"section":"history"},
4
+ {"section":"testunit"},
5
+ {"section":"intro"},
6
+ {"section":"tdd"},
7
+ {"section":"bdd"},
8
+ {"section":"mocking"},
9
+ {"section":"performance"},
10
+ {"section":"other"},
11
+ {"section":"closing"}
12
+ ]
13
+
@@ -0,0 +1,20 @@
1
+ !SLIDE small transition=turnDown
2
+
3
+ # TDD #
4
+
5
+ ## classic xunit ##
6
+
7
+ @@@ ruby
8
+ require 'minitest/autorun'
9
+ require 'post'
10
+
11
+ class TestPost < MiniTest::Unit::TestCase
12
+ def setup
13
+ @post = Post.new("minitest rockz")
14
+ end
15
+
16
+ def test_title
17
+ assert_equal("minitest rockz", @post.title)
18
+ end
19
+ end
20
+
@@ -0,0 +1,17 @@
1
+ !SLIDE commandline transition=turnDown
2
+
3
+ # TDD #
4
+
5
+ ## no runner, just ruby ##
6
+
7
+ $ ruby test_post.rb
8
+ Run options: --seed 954
9
+
10
+ # Running tests:
11
+
12
+ .
13
+
14
+ Finished tests in 0.000426s, 2347.4178 tests/s, 2347.4178 assertions/s.
15
+
16
+ 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
17
+
@@ -0,0 +1,23 @@
1
+ !SLIDE small transition=turnDown
2
+
3
+ # TDD #
4
+
5
+ ## assertions ##
6
+
7
+ $ gem install cheat
8
+ $ cheat minitest
9
+
10
+ minitest:
11
+ capture_io
12
+ flunk msg = nil
13
+ pass msg = nil
14
+ skip msg = nil, bt = caller
15
+
16
+ assert test, msg = nil
17
+ assert_equal exp, act, msg = nil
18
+ ...
19
+
20
+ refute test, msg = nil
21
+ refute_equal exp, act, msg = nil
22
+ ...
23
+
@@ -0,0 +1,24 @@
1
+ !SLIDE small transition=turnDown
2
+
3
+ # TDD #
4
+
5
+ ## skip, pass, flunk ##
6
+
7
+ @@@ruby
8
+ require 'minitest/autorun'
9
+
10
+ class TestFoo < MiniTest::Unit::TestCase
11
+ def test_skip
12
+ skip "can't figure why it's failing and it's 4pm"
13
+ assert_equal 1, 2
14
+ end
15
+
16
+ def test_flunk
17
+ flunk "forced failure"
18
+ end
19
+
20
+ def test_pass
21
+ 1000.times {pass "I get paid per assertion"}
22
+ end
23
+ end
24
+
@@ -0,0 +1,22 @@
1
+ !SLIDE small transition=turnDown
2
+
3
+ # TDD #
4
+
5
+ ## capture_io ##
6
+
7
+ @@@ruby
8
+ require 'minitest/autorun'
9
+ require 'dog'
10
+
11
+ class TestDog < MiniTest::Unit::TestCase
12
+ def setup
13
+ @dog = Dog.new
14
+ end
15
+
16
+ def test_speak
17
+ assert_output "bark\n", "" do
18
+ @dog.speak
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,8 @@
1
+ !SLIDE bullets incremental transition=turnDown
2
+
3
+ # What's wrong with test/unit? #
4
+
5
+ * slow (they say)
6
+ * bloated (I spose)
7
+ * neglected (definately)
8
+
@@ -0,0 +1,5 @@
1
+ !SLIDE transition=turnDown
2
+
3
+ # minitest #
4
+
5
+ ## so mini that I need slides ##
@@ -0,0 +1,18 @@
1
+ require 'minitest/autorun'
2
+ require 'edboxra'
3
+
4
+ class TestEdboxra < MiniTest::Unit::TestCase
5
+ def setup
6
+ @api = Edboxra::ApiFactory.new.create_api
7
+ end
8
+
9
+ def test_get_movies
10
+ movies = @api.get_movies
11
+ assert(movies.length > 0)
12
+ p "found #{movies.length} movies"
13
+
14
+ some_movie = movies[500]
15
+ @api.add_metadata_to(some_movie)
16
+ p some_movie
17
+ end
18
+ end
@@ -0,0 +1,53 @@
1
+ require 'webmock'
2
+
3
+ class FakeBox
4
+ VERSION_1_SNIPPET = <<-eos
5
+ <script src="include/gen3.15/PageableLayoutView.js" type="text/javascript"></script>
6
+ <input type="hidden" name="__K" id="__K" value="version_1_key" />
7
+ <table height="95%" width="100%" border="0" cellspacing="0" cellpadding="0">
8
+ <tr>
9
+ <td valign="top" align="center">
10
+ eos
11
+
12
+ VERSION_2_SNIPPET = <<-eos
13
+ </script>
14
+ <script src="/gen2.0.2/Scripts/s_code.js" type="text/javascript"></script><script src="/gen2.0.2/Scripts/rb.widget.buttonset.js" type="text/javascript"></script><script src="/gen2.0.2/Scripts/rb.widget.ministorefinder.js" type="text/javascript"></script><script src="/gen2.0.2/Scripts/jquery.bt.min-cust.js" type="text/javascript"></script><script src="/gen2.0.2/Scripts/rb.widget.basictooltip.js" type="text/javascript"></script><script src="/gen2.0.2/Scripts/rb.widget.slideshow.js" type="text/javascript"></script><script src="/gen2.0.2/Scripts/rb.widget.trailerplayer.js" type="text/javascript"></script><script src="/gen2.0.2/Scripts/rb.widget.newreleases.js" type="text/javascript"></script><script src="/gen2.0.2/Scripts/rb.widget.facebook.js" type="text/javascript"></script><script src="/gen2.0.2/Scripts/rb.widget.redblog.js" type="text/javascript"></script><script src="/gen2.0.2/Scripts/rb.widget.newsletter.js" type="text/javascript"></script><script type="text/javascript">rb.validation.init({"required":"This is a required field","cvv":"Invalid Cvv","password":"This is not a valid password, use 6-12 characters","email":"This is not a valid email","zip":"Invalid ZIP","phoneUS":"Please enter a valid phone number"})
15
+ rb.api.url = '/'; rb.api.key = 'version_2_key';</script><script type="text/javascript">$(document).ready(function() {rb.component.register('welcome0', rb.widget.welcome, {"loginUrl":"https://www.redbox.com/register?ReturnUrl=http%3a%2f%2fwww.redbox.com%2f","authUrl":["/account"],"rootUrl":"http://www.redbox.com","defaultUrl":"http://www.redbox.com","webAccountID":0,"firstName":"","urlPath":"/","type":"welcome","id":"welcome0","clientText":{"Welcome":"Welcome to redbox!","Hi":"Hi, {0}!","DialogTitle":"Welcome/Create an account"}});
16
+ rb.component.register('shoppingsession0', rb.widget.shoppingsession, {"cartUrl":"https://www.redbox.com/cart","showBlurayWarning":true,"maxItems":5,"data":{"session":{"storeRef":null,"items":[]}},"urlPath":"/","type":"shoppingsession","id":"shoppingsession0","clientText":{}});
17
+ $('.jqbutton').button();
18
+ rb.rec.Omn.Reco
19
+ eos
20
+
21
+ class << self
22
+ def fakeout_version_1
23
+ setup(VERSION_1_SNIPPET)
24
+ end
25
+
26
+ def fakeout_version_2
27
+ setup(VERSION_2_SNIPPET)
28
+ end
29
+
30
+ def expect_get(url, response)
31
+ WebMock \
32
+ .stub_request(:get, url) \
33
+ .to_return(:status => 200, :body => response)
34
+ end
35
+
36
+ def expect_post(url, content, headers, response)
37
+ WebMock \
38
+ .stub_request(:post, url) \
39
+ .with(:body => content, :headers => headers) \
40
+ .to_return(:status => 200, :body => response)
41
+ end
42
+
43
+ private
44
+
45
+ def setup(main_page)
46
+ WebMock.reset!
47
+ WebMock.disable_net_connect!
48
+ WebMock \
49
+ .stub_request(:get, "http://www.redbox.com/") \
50
+ .to_return(:status => 200, :body => main_page, :headers => {'Set-Cookie' => 'redboxVersion=foo; expires=Fri, 11-Mar-2011 02:02:51 GMT; path=/; HttpOnly'})
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,4 @@
1
+ class LogStub
2
+ def debug(msg)
3
+ end
4
+ end
@@ -0,0 +1,8 @@
1
+ require 'minitest/benchmark' if ENV['BENCH']
2
+ require 'minitest/autorun'
3
+ require 'edboxra'
4
+ require 'fake_box'
5
+ require 'log_stub'
6
+
7
+ class TestCase < MiniTest::Unit::TestCase
8
+ end
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ class TestApiFactory < TestCase
4
+ def setup
5
+ @log = MiniTest::Mock.new
6
+ @factory = Edboxra::ApiFactory.new(@log)
7
+ end
8
+
9
+ def test_gets_version_1_api
10
+ @log.expect :debug, "", ["found api key -- version_1_key"]
11
+ FakeBox.fakeout_version_1
12
+ assert_instance_of(Edboxra::V1::Api, @factory.create_api)
13
+ @log.verify
14
+ end
15
+
16
+ def test_gets_version_2_api
17
+ @log.expect :debug, "", ["found api key -- version_2_key"]
18
+ FakeBox.fakeout_version_2
19
+ assert_instance_of(Edboxra::V2::Api, @factory.create_api)
20
+ @log.verify
21
+ end
22
+
23
+ def bench_some_stuff_for_demonstration_purposes
24
+ assert_performance_linear 0.9999 do |n| # n is a range value
25
+ s = ""
26
+
27
+ n.times do
28
+ s << "x"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,61 @@
1
+ require 'test_helper'
2
+
3
+ class TestV1Api < TestCase
4
+ MOVIES_JS = 'Type.registerNamespace(\'rb.Cache\'); rb.Cache.__Title = [{"Cst":"0","ID":3942,"Name":"Red Hill","SortName":"red hill","Img":"RedHill_3942.jpg","Release":"20110125","GenreIDs":[1000,1003],"FormatID":"1","ProductType":"1","Def":"1","Limited":"0"},{"Cst":"0","ID":3956,"Name":"Saw: The Final Chapter","SortName":"saw: the final chapter","Img":"SawVII_3956.jpg","Release":"20110125","GenreIDs":[1009,1020,1093],"FormatID":"1","ProductType":"1","Def":"1","Limited":"0"},{"Cst":"0","ID":4385,"Name":"Takers (BLU-RAY)","SortName":"takers (blu-ray)","Img":"TakersBLURAY_4385.jpg","Release":"20110118","GenreIDs":[1000,1003,1022],"FormatID":"2","ProductType":"1","Def":"1","Limited":"0"}];'
5
+
6
+ def setup
7
+ FakeBox.fakeout_version_1
8
+ FakeBox.expect_get("http://www.redbox.com/data.svc/Title/js", MOVIES_JS)
9
+ @api = Edboxra::ApiFactory.new(LogStub.new).create_api
10
+ end
11
+
12
+ def test_get_movies
13
+ movies = @api.get_movies
14
+
15
+ assert_equal(3, movies.size)
16
+
17
+ assert_equal(3942, movies[0].id)
18
+ assert_equal("Red Hill", movies[0].name)
19
+ assert_equal("2011-01-25", movies[0].release_date.to_s)
20
+ assert_equal("RedHill_3942.jpg", movies[0].image)
21
+ assert_equal([1000, 1003], movies[0].genre_ids)
22
+ refute(movies[0].blu_ray?)
23
+ end
24
+
25
+ def test_get_blu_ray_movies
26
+ movies = @api.get_movies
27
+
28
+ assert_equal(4385, movies[2].id)
29
+ assert_equal("Takers (BLU-RAY)", movies[2].name)
30
+ assert(movies[2].blu_ray?)
31
+ end
32
+
33
+ def test_add_metadata
34
+ expected_content = JSON.generate({
35
+ :type => "Title",
36
+ :pk => "ID",
37
+ :statements => [{:filters => {:ID => 3942}}],
38
+ "__K" => "version_1_key"
39
+ })
40
+
41
+ expected_headers = {
42
+ :Cookie => 'redboxVersion=foo'
43
+ }
44
+
45
+ expected_response = '{"d":{"ID":4488,"Cst":"0","Name":"Big Momma\u0027s House (2000)","Img":"BigMommasHouse2000_4488.jpg","QtyRange":0,"Buy":"0","Price":7.0000,"Rating":"PG-13","RunningTime":"01:40","Actors":"Martin Lawrence, Nia Long","YahooRating":"B-","Desc":"Disguise is the limit. \"Martin Lawrence brings down the house\" (E! Online) as crafty FBI agent Malcolm Turner who\u0027s willing to go through thick and thin in order to catch an escaped prisoner. Sherry (Nia Long), the con\u0027s sexy former flame - she might have the skinny on millions in stolen loot, and she\u0027s headed for Georgia to lay low for a while. That\u0027s enough to send Malcolm deep undercover as Big Momma, an oversized, overbearing Southern granny with an attitude as tough as her pork chops. The result is an outrageous comedy of epic proportions, filled with nonstop laughs and plenty of action! \r\n \r\nRated PG-13 by the Motion Picture Association of America for crude humor including sexual innuendo, and for language and some violence. ","Genre":"Comedy","FormatID":"1","FormatName":"DVD","ProductType":"1","GameInstructionsURL":"","Trailers":{},"Ranks":{},"ReleaseDate":"February 08, 2011","Inv":null,"BuyDVDUrl":"","BuyBluRayUrl":"","Limited":"0"}}'
46
+
47
+ FakeBox.expect_post("http://www.redbox.com/data.svc/Title", expected_content, expected_headers, expected_response)
48
+
49
+ movies = @api.get_movies
50
+ red_hill = movies[0]
51
+ assert_nil(red_hill.description)
52
+
53
+ @api.add_metadata_to(red_hill)
54
+
55
+ refute_nil(red_hill.description)
56
+ assert_equal("PG-13", red_hill.rating)
57
+ assert_equal("01:40", red_hill.running_time)
58
+ assert_equal("Comedy", red_hill.genre)
59
+ assert_equal("Martin Lawrence, Nia Long", red_hill.actors)
60
+ end
61
+ end
@@ -0,0 +1,54 @@
1
+ require 'test_helper'
2
+
3
+ describe Edboxra::V2::Api do
4
+ MOVIES_JS = 'var __titles = [{"ID":3942,"soon":"0","name":"Red Hill","SEO":"red-hill","sortName":"red hill","img":"RedHill_3942.jpg","release":"20110125","releaseDays":16,"genreIDs":[1000,1003],"fmt":"1","productType":"1","rating":"R","def":"1","limited":"0"},{"ID":3956,"soon":"0","name":"Saw: The Final Chapter","SEO":"saw--the-final-chapter","sortName":"saw: the final chapter","img":"SawVII_3956.jpg","release":"20110125","releaseDays":16,"genreIDs":[1009,1020,1093],"fmt":"1","productType":"1","rating":"R","def":"1","limited":"0"},{"ID":4385,"soon":"0","name":"Takers (BLU-RAY)","SEO":"takers-blu-ray","sortName":"takers (blu-ray)","img":"TakersBLURAY_4385.jpg","release":"20110118","releaseDays":23,"genreIDs":[1000,1003,1022],"fmt":"2","productType":"1","rating":"R","def":"1","limited":"0"}]'
5
+
6
+ before do
7
+ FakeBox.fakeout_version_2
8
+ FakeBox.expect_get("http://www.redbox.com/api/product/js/__titles", MOVIES_JS)
9
+ @api = Edboxra::ApiFactory.new(LogStub.new).create_api
10
+ end
11
+
12
+ it "should get a list of movies" do
13
+ movies = @api.get_movies
14
+
15
+ movies.size.must_equal 3
16
+
17
+ red_hill = movies[0]
18
+ red_hill.id.must_equal 3942
19
+ red_hill.name.must_equal "Red Hill"
20
+ red_hill.release_date.to_s.must_equal "2011-01-25"
21
+ red_hill.image.must_equal "RedHill_3942.jpg"
22
+ red_hill.genre_ids.must_equal [1000, 1003]
23
+ red_hill.blu_ray?.must_equal false
24
+ end
25
+
26
+ it "should parse blu ray movies" do
27
+ movies = @api.get_movies
28
+
29
+ takers = movies[2]
30
+ takers.id.must_equal 4385
31
+ takers.blu_ray?.must_equal true
32
+ end
33
+
34
+ it "should add metadata" do
35
+ expected_content = JSON.generate({:productType => 1, :id => 3942, :descCharLimit => 2000})
36
+ expected_headers = {:Cookie => 'redboxVersion=foo', "__K" => "version_2_key"}
37
+ expected_response = '{"d":{"success":true,"msg":null,"data":{"productRef":3942,"productType":1,"image":"http://images.redbox.com/Images/Full/Cyrus_3963.jpg","name":"Cyrus","rating":"PG-13","ratingDesc":"Some material requires an accompanying parent or adult guardian.","fmt":"DVD","len":"01:40","desc":"John C. Reilly, Jonah Hill and Oscar Winner Marisa Tomei star in this quirky, hilarious story about love, family and cutting the cord. Not-so-recently divorced John (Reilly) thinks hes finally found the perfect woman when he meets the sweet and sexy Molly (Tomei). Theres just one problem Moll...","genre":["Comedy"],"starring":["Martin Lawrence, Nia Long"],"director":"Jay Duplass"}}}'
38
+
39
+ FakeBox.expect_post("http://www.redbox.com/api/Product/GetDetail/", expected_content, expected_headers, expected_response)
40
+
41
+ movies = @api.get_movies
42
+ red_hill = movies[0]
43
+ red_hill.description.must_be_nil
44
+
45
+ @api.add_metadata_to(red_hill)
46
+
47
+ red_hill.description.wont_be_nil
48
+ red_hill.rating.must_equal "PG-13"
49
+ red_hill.running_time.must_equal "01:40"
50
+ red_hill.genre.must_equal "Comedy"
51
+ red_hill.actors.must_equal "Martin Lawrence, Nia Long"
52
+ end
53
+ end
54
+
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: edboxra
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Darrin Holst
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-02-16 00:00:00 -06:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rest-client
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: "1.6"
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: "1.5"
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: webmock
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: "1.6"
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: minitest
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: "2.0"
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: ZenTest
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: "4.4"
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: autotest-growl
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: "0.2"
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: autotest-fsevent
84
+ requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: "0.2"
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *id007
93
+ description: Interface to some movie box place
94
+ email:
95
+ - darrinholst@gmail.com
96
+ executables: []
97
+
98
+ extensions: []
99
+
100
+ extra_rdoc_files: []
101
+
102
+ files:
103
+ - .autotest
104
+ - .gitignore
105
+ - .rvmrc
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE
109
+ - README
110
+ - Rakefile
111
+ - edboxra.gemspec
112
+ - lib/edboxra.rb
113
+ - lib/edboxra/api.rb
114
+ - lib/edboxra/api_factory.rb
115
+ - lib/edboxra/movie.rb
116
+ - lib/edboxra/v1/v1_api.rb
117
+ - lib/edboxra/v2/v2_api.rb
118
+ - lib/edboxra/version.rb
119
+ - showoff/bdd/01_we_love_bdd.md
120
+ - showoff/bdd/02_structure.md
121
+ - showoff/bdd/03_expectations.md
122
+ - showoff/closing/01_closing.md
123
+ - showoff/custom.css
124
+ - showoff/history/01_history.md
125
+ - showoff/intro/01_write_your_own.md
126
+ - showoff/intro/02_in_the_box.md
127
+ - showoff/mocking/01_got_mock.md
128
+ - showoff/mocking/02_simple.md
129
+ - showoff/mocking/03_example.md
130
+ - showoff/other/01_other.md
131
+ - showoff/other/02_randomization.md
132
+ - showoff/other/FIRST.jpg
133
+ - showoff/performance/01_build_right_in.md
134
+ - showoff/performance/02_add_to_tests.md
135
+ - showoff/performance/03_example.md
136
+ - showoff/performance/04_assertions.md
137
+ - showoff/showoff.json
138
+ - showoff/tdd/01_structure.md
139
+ - showoff/tdd/02_run_it.md
140
+ - showoff/tdd/03_assertions.md
141
+ - showoff/tdd/04_skip_pass_flunk.md
142
+ - showoff/tdd/05_capture_io.md
143
+ - showoff/testunit/01_whats_wrong.md
144
+ - showoff/title/01_title.md
145
+ - test/integration/test_edboxra.rb
146
+ - test/unit/helpers/fake_box.rb
147
+ - test/unit/helpers/log_stub.rb
148
+ - test/unit/helpers/test_helper.rb
149
+ - test/unit/test_api_factory.rb
150
+ - test/unit/v1/test_v1_api.rb
151
+ - test/unit/v2/test_v2_api.rb
152
+ has_rdoc: true
153
+ homepage: http://github.com/darrinholst/edboxra
154
+ licenses: []
155
+
156
+ post_install_message:
157
+ rdoc_options: []
158
+
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ none: false
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ hash: -3208009633172794345
167
+ segments:
168
+ - 0
169
+ version: "0"
170
+ required_rubygems_version: !ruby/object:Gem::Requirement
171
+ none: false
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ hash: -3208009633172794345
176
+ segments:
177
+ - 0
178
+ version: "0"
179
+ requirements: []
180
+
181
+ rubyforge_project: edboxra
182
+ rubygems_version: 1.5.0
183
+ signing_key:
184
+ specification_version: 3
185
+ summary: Interface to some movie box place
186
+ test_files:
187
+ - test/integration/test_edboxra.rb
188
+ - test/unit/helpers/fake_box.rb
189
+ - test/unit/helpers/log_stub.rb
190
+ - test/unit/helpers/test_helper.rb
191
+ - test/unit/test_api_factory.rb
192
+ - test/unit/v1/test_v1_api.rb
193
+ - test/unit/v2/test_v2_api.rb