fb_graph-mock 0.0.0 → 0.0.1
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.
- data/README.rdoc +81 -0
- data/VERSION +1 -1
- data/fb_graph-mock.gemspec +0 -1
- data/lib/fb_graph/mock.rb +17 -13
- metadata +3 -19
- data/README.md +0 -29
data/README.rdoc
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
= FbGraph::Mock
|
2
|
+
|
3
|
+
Facebook Graph API mocking helper, originally used in fb_graph gem.
|
4
|
+
|
5
|
+
This gem simply mock HTTP request & response using webmock gem, and returns pre-registered JSON response.
|
6
|
+
|
7
|
+
It means you can use fb_graph-mock gem even with kwala, rest-client, or any other code which access to Facebook Graph API.
|
8
|
+
|
9
|
+
== Installation
|
10
|
+
|
11
|
+
gem install fb_graph-mock
|
12
|
+
|
13
|
+
== Examples
|
14
|
+
|
15
|
+
In spec_helper.rb
|
16
|
+
|
17
|
+
require 'fb_graph/mock'
|
18
|
+
include FbGraph::Mock
|
19
|
+
WebMock.disable_net_connect! # Optional
|
20
|
+
|
21
|
+
In foo_spec.rb
|
22
|
+
|
23
|
+
it do
|
24
|
+
mock_graph :get, 'me', 'users/me_private', :access_token => 'access_token' do
|
25
|
+
user = FbGraph::User.me('access_token').fetch
|
26
|
+
user.website.should == 'http://matake.jp'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it do
|
31
|
+
mock_graph :get, 'me', 'users/me_public', :status => [401, 'Unauthorized'] do
|
32
|
+
lambda do
|
33
|
+
FbGraph::User.fetch :me
|
34
|
+
end.should raise_error FbGraph::Unauthorized
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
=== More Examples?
|
39
|
+
|
40
|
+
You can see lots of samples in fb_graph's specs.
|
41
|
+
https://github.com/nov/fb_graph
|
42
|
+
|
43
|
+
== Registered Mocks and Your Custom Mocks
|
44
|
+
|
45
|
+
To improve fb_graph and other projects using this gem, keeping mock JSONs are important.
|
46
|
+
|
47
|
+
If you find any legacy response format in this gem's mock_json directory, please report an issue or send a pull request with new JSON file.
|
48
|
+
|
49
|
+
You can find all registered responses as below.
|
50
|
+
|
51
|
+
FbGraph::Mock.registered_mocks
|
52
|
+
|
53
|
+
If it's hard to share your mock JSON (e.g. because of privacy issue), you can use your own response file as below.
|
54
|
+
|
55
|
+
file_path = File.join(Rails.root, 'spec/my_own_mock_json/users/me_private.json')
|
56
|
+
mock_graph :get, 'me', file_path do
|
57
|
+
# Do something.
|
58
|
+
end
|
59
|
+
|
60
|
+
If a file is found at the given file path, this gem uses the file.
|
61
|
+
|
62
|
+
Otherwise, this gem search a registered mock JSON file in its own registry.
|
63
|
+
|
64
|
+
mock_graph :get, 'me', 'users/albums/arjun_public' do
|
65
|
+
# => uses "mock_json/users/albums/arjun_public.json" in this gem.
|
66
|
+
# Do something.
|
67
|
+
end
|
68
|
+
|
69
|
+
== Note on Patches/Pull Requests
|
70
|
+
|
71
|
+
* Fork the project.
|
72
|
+
* Make your feature addition or bug fix.
|
73
|
+
* Add tests for it. This is important so I don't break it in a
|
74
|
+
future version unintentionally.
|
75
|
+
* Commit, do not mess with rakefile, version, or history.
|
76
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
77
|
+
* Send me a pull request. Bonus points for topic branches.
|
78
|
+
|
79
|
+
== Copyright
|
80
|
+
|
81
|
+
Copyright (c) 2012 nov matake. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
data/fb_graph-mock.gemspec
CHANGED
@@ -10,7 +10,6 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
11
11
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
12
12
|
gem.require_paths = ["lib"]
|
13
|
-
gem.add_runtime_dependency "json"
|
14
13
|
gem.add_runtime_dependency "fb_graph"
|
15
14
|
gem.add_runtime_dependency "rspec"
|
16
15
|
gem.add_runtime_dependency "webmock"
|
data/lib/fb_graph/mock.rb
CHANGED
@@ -12,14 +12,16 @@ module FbGraph
|
|
12
12
|
).to_return(
|
13
13
|
response_for(response_path, options)
|
14
14
|
)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
if block_given?
|
16
|
+
response = yield
|
17
|
+
a_request(
|
18
|
+
method,
|
19
|
+
endpoint_for(path)
|
20
|
+
).with(
|
21
|
+
request_for(method, options)
|
22
|
+
).should have_been_made.once
|
23
|
+
response
|
24
|
+
end
|
23
25
|
end
|
24
26
|
|
25
27
|
def mock_fql(query, response_file, options = {})
|
@@ -31,11 +33,13 @@ module FbGraph
|
|
31
33
|
).to_return(
|
32
34
|
response_for(response_file, options)
|
33
35
|
)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
if block_given?
|
37
|
+
response = yield
|
38
|
+
a_request(:get, FbGraph::Query.new(query).endpoint).with(
|
39
|
+
request_for(:get, options)
|
40
|
+
).should have_been_made.once
|
41
|
+
response
|
42
|
+
end
|
39
43
|
end
|
40
44
|
|
41
45
|
def request_to(path, method = :get)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fb_graph-mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: json
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
30
14
|
- !ruby/object:Gem::Dependency
|
31
15
|
name: fb_graph
|
32
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,7 +85,7 @@ files:
|
|
101
85
|
- .gitignore
|
102
86
|
- Gemfile
|
103
87
|
- LICENSE.txt
|
104
|
-
- README.
|
88
|
+
- README.rdoc
|
105
89
|
- Rakefile
|
106
90
|
- VERSION
|
107
91
|
- fb_graph-mock.gemspec
|
data/README.md
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# FbGraph::Mock
|
2
|
-
|
3
|
-
TODO: Write a gem description
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
gem 'fb_graph-mock'
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
Or install it yourself as:
|
16
|
-
|
17
|
-
$ gem install fb_graph-mock
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
|
-
## Contributing
|
24
|
-
|
25
|
-
1. Fork it
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|