roar 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +14 -6
  3. data/CHANGES.markdown +75 -58
  4. data/CONTRIBUTING.md +31 -0
  5. data/Gemfile +12 -2
  6. data/ISSUE_TEMPLATE.md +20 -0
  7. data/LICENSE +1 -1
  8. data/README.markdown +126 -250
  9. data/Rakefile +3 -1
  10. data/examples/example.rb +0 -0
  11. data/examples/example_server.rb +0 -0
  12. data/lib/roar.rb +3 -3
  13. data/lib/roar/client.rb +8 -3
  14. data/lib/roar/decorator.rb +2 -2
  15. data/lib/roar/http_verbs.rb +0 -16
  16. data/lib/roar/hypermedia.rb +30 -56
  17. data/lib/roar/json.rb +5 -5
  18. data/lib/roar/json/collection.rb +10 -2
  19. data/lib/roar/json/hal.rb +72 -82
  20. data/lib/roar/version.rb +1 -1
  21. data/lib/roar/xml.rb +1 -1
  22. data/roar.gemspec +6 -6
  23. data/test/client_test.rb +1 -1
  24. data/test/coercion_feature_test.rb +7 -2
  25. data/test/decorator_test.rb +17 -7
  26. data/test/hal_json_test.rb +98 -106
  27. data/test/hypermedia_feature_test.rb +13 -31
  28. data/test/hypermedia_test.rb +26 -92
  29. data/test/{decorator_client_test.rb → integration/decorator_client_test.rb} +5 -4
  30. data/test/{faraday_http_transport_test.rb → integration/faraday_http_transport_test.rb} +1 -0
  31. data/test/{http_verbs_test.rb → integration/http_verbs_test.rb} +3 -2
  32. data/test/integration/json_collection_test.rb +35 -0
  33. data/test/{net_http_transport_test.rb → integration/net_http_transport_test.rb} +1 -0
  34. data/test/integration/runner.rb +2 -3
  35. data/test/integration/server.rb +6 -0
  36. data/test/json_representer_test.rb +2 -29
  37. data/test/lonely_test.rb +1 -2
  38. data/test/ssl_client_certs_test.rb +1 -1
  39. data/test/test_helper.rb +21 -3
  40. data/test/xml_representer_test.rb +6 -5
  41. metadata +22 -36
  42. data/gemfiles/Gemfile.representable-1.7 +0 -6
  43. data/gemfiles/Gemfile.representable-1.8 +0 -6
  44. data/gemfiles/Gemfile.representable-2.0 +0 -5
  45. data/gemfiles/Gemfile.representable-2.1 +0 -5
  46. data/gemfiles/Gemfile.representable-head +0 -6
  47. data/lib/roar/json/collection_json.rb +0 -208
  48. data/lib/roar/json/json_api.rb +0 -233
  49. data/test/collection_json_test.rb +0 -132
  50. data/test/hal_links_test.rb +0 -31
  51. data/test/json_api_test.rb +0 -451
  52. data/test/lib/runner.rb +0 -134
@@ -1,134 +0,0 @@
1
- require 'open-uri'
2
- require 'net/http'
3
- require 'timeout'
4
-
5
- # Helps you spinning up and shutting down your own sinatra app. This is especially helpful for running
6
- # real network tests against a sinatra backend.
7
- #
8
- # The backend server could look like the following (in test/server.rb).
9
- #
10
- # require "sinatra"
11
- #
12
- # get "/" do
13
- # "Cheers from test server"
14
- # end
15
- #
16
- # get "/ping" do
17
- # "1"
18
- # end
19
- #
20
- # Note that you need to implement a ping action for internal use.
21
- #
22
- # Next, you need to write your runner.
23
- #
24
- # require 'sinatra/runner'
25
- #
26
- # class Runner < Sinatra::Runner
27
- # def app_file
28
- # File.expand_path("../server.rb", __FILE__)
29
- # end
30
- # end
31
- #
32
- # Override Runner#app_file, #command, #port, #protocol and #ping_path for customization.
33
- #
34
- # Whereever you need this test backend, here's how you manage it. The following example assumes you
35
- # have a test in your app that needs to be run against your test backend.
36
- #
37
- # runner = ServerRunner.new
38
- # runner.run
39
- #
40
- # # ..tests against localhost:4567 here..
41
- #
42
- # runner.kill
43
- #
44
- # For an example, check https://github.com/apotonick/roar/blob/master/test/test_helper.rb
45
- module Sinatra
46
- class Runner
47
- def app_file
48
- File.expand_path("../server.rb", __FILE__)
49
- end
50
-
51
- def run
52
- #puts command
53
- @pipe = start
54
- @started = Time.now
55
- warn "#{server} up and running on port #{port}" if ping
56
- end
57
-
58
- def kill
59
- return unless pipe
60
- Process.kill("KILL", pipe.pid)
61
- rescue NotImplementedError
62
- system "kill -9 #{pipe.pid}"
63
- rescue Errno::ESRCH
64
- end
65
-
66
- def get(url)
67
- Timeout.timeout(1) { get_url("#{protocol}://127.0.0.1:#{port}#{url}") }
68
- end
69
-
70
- def log
71
- @log ||= ""
72
- loop { @log << pipe.read_nonblock(1) }
73
- rescue Exception
74
- @log
75
- end
76
-
77
- private
78
- attr_accessor :pipe
79
-
80
- def start
81
- IO.popen(command)
82
- end
83
-
84
- def command # to be overwritten
85
- "bundle exec ruby #{app_file} -p #{port} -e production"
86
- end
87
-
88
- def ping(timeout=30)
89
- loop do
90
- return if alive?
91
- if Time.now - @started > timeout
92
- $stderr.puts command, log
93
- fail "timeout"
94
- else
95
- sleep 0.1
96
- end
97
- end
98
- end
99
-
100
- def alive?
101
- 3.times { get(ping_path) }
102
- true
103
- rescue Errno::ECONNREFUSED, Errno::ECONNRESET, EOFError, SystemCallError, OpenURI::HTTPError, Timeout::Error
104
- false
105
- end
106
-
107
- def ping_path # to be overwritten
108
- '/ping'
109
- end
110
-
111
- def port # to be overwritten
112
- 4567
113
- end
114
-
115
- def protocol
116
- "http"
117
- end
118
-
119
- def get_url(url)
120
- uri = URI.parse(url)
121
-
122
- return uri.read unless protocol == "https"
123
- get_https_url(uri)
124
- end
125
-
126
- def get_https_url(uri)
127
- http = Net::HTTP.new(uri.host, uri.port)
128
- http.use_ssl = true
129
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
130
- request = Net::HTTP::Get.new(uri.request_uri)
131
- http.request(request).body
132
- end
133
- end
134
- end