webmock_method 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/.idea/.name +1 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/jenkinsSettings.xml +9 -0
- data/.idea/misc.xml +6 -0
- data/.idea/modules.xml +9 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/vcs.xml +7 -0
- data/.idea/webmock_method.iml +205 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CHANGES +7 -0
- data/Gemfile +23 -0
- data/LICENSE +20 -0
- data/LICENSE.txt +22 -0
- data/README.md +134 -0
- data/Rakefile +42 -0
- data/lib/meta_methods/meta_methods.rb +15 -0
- data/lib/webmock_method/render_helper.rb +16 -0
- data/lib/webmock_method/version.rb +3 -0
- data/lib/webmock_method/webmock_method.rb +45 -0
- data/lib/webmock_method.rb +3 -0
- data/spec/meta_methods_spec.rb +28 -0
- data/spec/open_weather_map_service_spec.rb +45 -0
- data/spec/payment_gateway_spec.rb +44 -0
- data/spec/services/payment_gateway.rb +57 -0
- data/spec/services/templates/purchase_request.xml.erb +13 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/stubs/payment_gateway.rb +19 -0
- data/spec/stubs/templates/purchase_response.xml.erb +7 -0
- data/spec/stubs/templates/quote_response.json.erb +38 -0
- data/webmock_method.gemspec.erb +24 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NDYzOWUwYzU1MTQ2NmUwM2Y0MzE2ZDBjYTFkMDgwYjAyZTQzNzFhYQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NTA2MDY5Y2VlZGE3ZjVhNjI4NmZkOGMwNjk5M2MwNzVmODA3NjgyNQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YWJiMjQwNGNkNWI5ZGFhNDY4N2MyYTNhYWI3N2Q1N2RiNjc1ZjY1NDBkMmJl
|
10
|
+
NmE0Y2FhOTAxMjc2YTZhNDE0NGQyMGFiZWViYjJmMGE0OWI1ZWU3OGVjZTdj
|
11
|
+
Mjc0NzVjYWUwNTkxZDI4ZTZkZjM4NzE4YTRmNGM1NmJiYmJjMTM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NzFmMWY2YmU1YTVmNTA0ZmNlOTJhZGFkZmQ4ZmYzMzAzZGUyMzU0MDkzMzEy
|
14
|
+
NDVlN2ZiYWU3YzI1MGZhY2MzMmU4MTJkYWFiY2MxNDA1MGNjMmQyNWU1MGRk
|
15
|
+
MDNjYmU3M2ZmMDYyYzMyNDU2NzAzNjNiODhiNTc0MjI2OTk2MWE=
|
data/.gitignore
ADDED
data/.idea/.name
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
webmock_method
|
data/.idea/.rakeTasks
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<Settings><!--This file was automatically generated by Ruby plugin.
|
3
|
+
You are allowed to:
|
4
|
+
1. Remove rake task
|
5
|
+
2. Add existing rake tasks
|
6
|
+
To add existing rake tasks automatically delete this file and reload the project.
|
7
|
+
--><RakeGroup description="" fullCmd="" taksId="rake" /></Settings>
|
data/.idea/encodings.xml
ADDED
data/.idea/misc.xml
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="CppTools.Loader" reportImplicitCastToBool="false" reportNameReferencedOnce="false" version="3" compilerSelect="AUTO" />
|
4
|
+
<component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-2.0.0-p195 [resource_accessor]" project-jdk-type="RUBY_SDK" />
|
5
|
+
</project>
|
6
|
+
|
data/.idea/modules.xml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/webmock_method.iml" filepath="$PROJECT_DIR$/.idea/webmock_method.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
9
|
+
|
data/.idea/vcs.xml
ADDED
@@ -0,0 +1,205 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="FacetManager">
|
4
|
+
<facet type="gem" name="Gem">
|
5
|
+
<configuration>
|
6
|
+
<option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
|
7
|
+
<option name="GEM_APP_TEST_PATH" value="" />
|
8
|
+
<option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
|
9
|
+
</configuration>
|
10
|
+
</facet>
|
11
|
+
</component>
|
12
|
+
<component name="ModuleRunConfigurationManager">
|
13
|
+
<configuration default="false" name="PaymentGateway: webmock_method" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
|
14
|
+
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
|
15
|
+
<module name="webmock_method" />
|
16
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
17
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$" />
|
18
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
|
19
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
|
20
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" />
|
21
|
+
<envs>
|
22
|
+
<env name="JRUBY_OPTS" value="-X+O" />
|
23
|
+
</envs>
|
24
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="false" />
|
25
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
26
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
|
27
|
+
<COVERAGE_PATTERN ENABLED="true">
|
28
|
+
<PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
|
29
|
+
</COVERAGE_PATTERN>
|
30
|
+
</EXTENSION>
|
31
|
+
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
|
32
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" />
|
33
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/payment_gateway_spec.rb" />
|
34
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
|
35
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
|
36
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="PaymentGateway" />
|
37
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
|
38
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
|
39
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
|
40
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" />
|
41
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" />
|
42
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" />
|
43
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" />
|
44
|
+
<RunnerSettings RunnerId="RubyDebugRunner" />
|
45
|
+
<RunnerSettings RunnerId="RubyRunner" />
|
46
|
+
<ConfigurationWrapper RunnerId="RubyDebugRunner" />
|
47
|
+
<ConfigurationWrapper RunnerId="RubyRunner" />
|
48
|
+
<method />
|
49
|
+
</configuration>
|
50
|
+
<configuration default="false" name="open_weather_spec: webmock_method" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
|
51
|
+
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
|
52
|
+
<module name="webmock_method" />
|
53
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
54
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$" />
|
55
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
|
56
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
|
57
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" />
|
58
|
+
<envs>
|
59
|
+
<env name="JRUBY_OPTS" value="-X+O" />
|
60
|
+
</envs>
|
61
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="false" />
|
62
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
63
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
|
64
|
+
<COVERAGE_PATTERN ENABLED="true">
|
65
|
+
<PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
|
66
|
+
</COVERAGE_PATTERN>
|
67
|
+
</EXTENSION>
|
68
|
+
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
|
69
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" />
|
70
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/open_weather_map_service_spec.rb" />
|
71
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
|
72
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
|
73
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" />
|
74
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
|
75
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
|
76
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
|
77
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" />
|
78
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" />
|
79
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" />
|
80
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" />
|
81
|
+
<RunnerSettings RunnerId="RubyDebugRunner" />
|
82
|
+
<RunnerSettings RunnerId="RubyRunner" />
|
83
|
+
<ConfigurationWrapper RunnerId="RubyDebugRunner" />
|
84
|
+
<ConfigurationWrapper RunnerId="RubyRunner" />
|
85
|
+
<method />
|
86
|
+
</configuration>
|
87
|
+
<configuration default="false" name="payment_gateway" type="RubyRunConfigurationType" factoryName="Ruby" temporary="true">
|
88
|
+
<module name="webmock_method" />
|
89
|
+
<RUBY_RUN_CONFIG NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
90
|
+
<RUBY_RUN_CONFIG NAME="WORK DIR" VALUE="$MODULE_DIR$/spec/stubs" />
|
91
|
+
<RUBY_RUN_CONFIG NAME="SHOULD_USE_SDK" VALUE="false" />
|
92
|
+
<RUBY_RUN_CONFIG NAME="ALTERN_SDK_NAME" VALUE="" />
|
93
|
+
<RUBY_RUN_CONFIG NAME="myPassParentEnvs" VALUE="true" />
|
94
|
+
<envs />
|
95
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="false" />
|
96
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
97
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
|
98
|
+
<COVERAGE_PATTERN ENABLED="true">
|
99
|
+
<PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
|
100
|
+
</COVERAGE_PATTERN>
|
101
|
+
</EXTENSION>
|
102
|
+
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
|
103
|
+
<RUBY_RUN_CONFIG NAME="SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/stubs/payment_gateway.rb" />
|
104
|
+
<RUBY_RUN_CONFIG NAME="SCRIPT_ARGS" VALUE="" />
|
105
|
+
<RunnerSettings RunnerId="RubyRunner" />
|
106
|
+
<ConfigurationWrapper RunnerId="RubyRunner" />
|
107
|
+
<method />
|
108
|
+
</configuration>
|
109
|
+
<configuration default="false" name="OpenWeather#quote tests: webmock_method" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
|
110
|
+
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
|
111
|
+
<module name="webmock_method" />
|
112
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
113
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$" />
|
114
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
|
115
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
|
116
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" />
|
117
|
+
<envs>
|
118
|
+
<env name="JRUBY_OPTS" value="-X+O" />
|
119
|
+
</envs>
|
120
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="false" />
|
121
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
122
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
|
123
|
+
<COVERAGE_PATTERN ENABLED="true">
|
124
|
+
<PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
|
125
|
+
</COVERAGE_PATTERN>
|
126
|
+
</EXTENSION>
|
127
|
+
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
|
128
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" />
|
129
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/open_weather_map_service_spec.rb" />
|
130
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
|
131
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
|
132
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="OpenWeather#quote tests" />
|
133
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
|
134
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
|
135
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
|
136
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" />
|
137
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" />
|
138
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" />
|
139
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" />
|
140
|
+
<RunnerSettings RunnerId="RubyRunner" />
|
141
|
+
<ConfigurationWrapper RunnerId="RubyRunner" />
|
142
|
+
<method />
|
143
|
+
</configuration>
|
144
|
+
<configuration default="false" name="payment_gateway_spec: webmock_method" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
|
145
|
+
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
|
146
|
+
<module name="webmock_method" />
|
147
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
148
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$" />
|
149
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
|
150
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
|
151
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" />
|
152
|
+
<envs>
|
153
|
+
<env name="JRUBY_OPTS" value="-X+O" />
|
154
|
+
</envs>
|
155
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="false" />
|
156
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
157
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
|
158
|
+
<COVERAGE_PATTERN ENABLED="true">
|
159
|
+
<PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
|
160
|
+
</COVERAGE_PATTERN>
|
161
|
+
</EXTENSION>
|
162
|
+
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
|
163
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" />
|
164
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/payment_gateway_spec.rb" />
|
165
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
|
166
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
|
167
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" />
|
168
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
|
169
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
|
170
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
|
171
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" />
|
172
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" />
|
173
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" />
|
174
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" />
|
175
|
+
<RunnerSettings RunnerId="RubyRunner" />
|
176
|
+
<ConfigurationWrapper RunnerId="RubyRunner" />
|
177
|
+
<method />
|
178
|
+
</configuration>
|
179
|
+
</component>
|
180
|
+
<component name="NewModuleRootManager">
|
181
|
+
<content url="file://$MODULE_DIR$/../docs" />
|
182
|
+
<content url="file://$MODULE_DIR$" />
|
183
|
+
<orderEntry type="jdk" jdkName="RVM: ruby-1.9.3-p448 [webmock_method]" jdkType="RUBY_SDK" />
|
184
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
185
|
+
<orderEntry type="library" scope="PROVIDED" name="addressable (v2.3.5, RVM: ruby-1.9.3-p448 [webmock_method]) [gem]" level="application" />
|
186
|
+
<orderEntry type="library" scope="PROVIDED" name="awesome_print (v1.2.0, RVM: ruby-1.9.3-p448 [webmock_method]) [gem]" level="application" />
|
187
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.3.5, RVM: ruby-1.9.3-p448 [webmock_method]) [gem]" level="application" />
|
188
|
+
<orderEntry type="library" scope="PROVIDED" name="crack (v0.4.1, RVM: ruby-1.9.3-p448 [webmock_method]) [gem]" level="application" />
|
189
|
+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.4, RVM: ruby-1.9.3-p448 [webmock_method]) [gem]" level="application" />
|
190
|
+
<orderEntry type="library" scope="PROVIDED" name="file_utils (v1.0.7, RVM: ruby-1.9.3-p448 [webmock_method]) [gem]" level="application" />
|
191
|
+
<orderEntry type="library" scope="PROVIDED" name="gemcutter (v0.7.1, RVM: ruby-1.9.3-p448 [webmock_method]) [gem]" level="application" />
|
192
|
+
<orderEntry type="library" scope="PROVIDED" name="gemspec_deps_gen (v1.1.2, RVM: ruby-1.9.3-p448 [webmock_method]) [gem]" level="application" />
|
193
|
+
<orderEntry type="library" scope="PROVIDED" name="json_pure (v1.8.1, RVM: ruby-1.9.3-p448 [webmock_method]) [gem]" level="application" />
|
194
|
+
<orderEntry type="library" scope="PROVIDED" name="metaclass (v0.0.1, RVM: ruby-1.9.3-p448 [webmock_method]) [gem]" level="application" />
|
195
|
+
<orderEntry type="library" scope="PROVIDED" name="mocha (v0.14.0, RVM: ruby-1.9.3-p448 [webmock_method]) [gem]" level="application" />
|
196
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v2.14.1, RVM: ruby-1.9.3-p448 [webmock_method]) [gem]" level="application" />
|
197
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v2.14.6, RVM: ruby-1.9.3-p448 [webmock_method]) [gem]" level="application" />
|
198
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v2.14.3, RVM: ruby-1.9.3-p448 [webmock_method]) [gem]" level="application" />
|
199
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v2.14.4, RVM: ruby-1.9.3-p448 [webmock_method]) [gem]" level="application" />
|
200
|
+
<orderEntry type="library" scope="PROVIDED" name="safe_yaml (v0.9.7, RVM: ruby-1.9.3-p448 [webmock_method]) [gem]" level="application" />
|
201
|
+
<orderEntry type="library" scope="PROVIDED" name="webmock (v1.15.0, RVM: ruby-1.9.3-p448 [webmock_method]) [gem]" level="application" />
|
202
|
+
<orderEntry type="library" scope="PROVIDED" name="xml-simple (v1.1.2, RVM: ruby-1.9.3-p448 [webmock_method]) [gem]" level="application" />
|
203
|
+
</component>
|
204
|
+
</module>
|
205
|
+
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
webmock_method
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3
|
data/CHANGES
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
group :default do
|
4
|
+
gem "webmock"
|
5
|
+
end
|
6
|
+
|
7
|
+
group :development do
|
8
|
+
gem "gemspec_deps_gen"
|
9
|
+
gem "gemcutter"
|
10
|
+
end
|
11
|
+
|
12
|
+
group :test do
|
13
|
+
gem "rspec"
|
14
|
+
gem "mocha"
|
15
|
+
gem "xml-simple"
|
16
|
+
gem "json_pure"
|
17
|
+
gem "awesome_print"
|
18
|
+
end
|
19
|
+
|
20
|
+
#group :debug do
|
21
|
+
# gem "ruby-debug-base19x", "0.11.30.pre12"
|
22
|
+
# gem "ruby-debug-ide", "0.4.17"
|
23
|
+
#end
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Alexander Shvets
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Alexander Shvets
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
# Webmock Method
|
2
|
+
|
3
|
+
Gem-extension for webmock gem for creating services with mocked methods.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'webmock_method'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install webmock_method
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
[WebMock] (https://github.com/bblimke/webmock) is gem for stubbing HTTP requests. You can use
|
22
|
+
it in your tests if you don't want to hit actual service while testing other functionality of your service.
|
23
|
+
For example:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'webmock'
|
27
|
+
|
28
|
+
WebMock.stub_request(:any, "www.example.com").to_return(:body => "some body")
|
29
|
+
|
30
|
+
puts Net::HTTP.get("www.example.com", "/") # some body
|
31
|
+
```
|
32
|
+
|
33
|
+
It will stub all http verbs (GET, POST, PUT etc.) thanks to **:any** parameter.
|
34
|
+
|
35
|
+
You can also use webmock library for building **stubbed versions** of your services. This approach is especially
|
36
|
+
useful when services to be called **are not implemented yet** (maybe by another team) and you still
|
37
|
+
want to start working on your part and finish it on time.
|
38
|
+
|
39
|
+
In order to facilitate the creation of **mocked service methods**, you can use **webmock_method** gem.
|
40
|
+
|
41
|
+
How to use it?
|
42
|
+
|
43
|
+
First, create **actual service wrapper** that works with future API of "not yet developed service". As an example,
|
44
|
+
we can use publicly available [OpenWeatherMap](http://api.openweathermap.org) web service.
|
45
|
+
|
46
|
+
We will implement call to **quote weather** for a given city. You have to provide **location** and **units** parameters:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
# services/open_weather_map_service.rb
|
50
|
+
|
51
|
+
require 'net/http'
|
52
|
+
|
53
|
+
class OpenWeatherMapService
|
54
|
+
attr_reader :url
|
55
|
+
|
56
|
+
def initialize
|
57
|
+
@url = 'http://api.openweathermap.org/data/2.5/weather'
|
58
|
+
end
|
59
|
+
|
60
|
+
def quote location, units
|
61
|
+
quote_url = "#{url}?q=#{location}%20nj&units=#{units}"
|
62
|
+
|
63
|
+
uri = URI.parse(URI.escape(quote_url))
|
64
|
+
|
65
|
+
Net::HTTP.get(uri) # At this moment, service is not developed yet...
|
66
|
+
end
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
Then, create stub/mock for your service:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
# stubs/open_weather_map_service.rb
|
74
|
+
|
75
|
+
require 'webmock_method'
|
76
|
+
require 'json'
|
77
|
+
|
78
|
+
require 'services/open_weather_map_service.rb'
|
79
|
+
|
80
|
+
class OpenWeatherMapService
|
81
|
+
extend WebmockMethod
|
82
|
+
|
83
|
+
webmock_method :quote, [:location, :units], lambda { |binding|
|
84
|
+
RenderHelper.render :json, "#{File.dirname(__FILE__)}/stubs/templates/quote_response.json.erb", binding
|
85
|
+
}, /#{WebmockMethod.url}/
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
**webmock_method** requires you to provide the following information:
|
90
|
+
|
91
|
+
* **method name** to be mocked;
|
92
|
+
* **parameters names** for the method (same as in original service);
|
93
|
+
* **proc/lambda** expression for building the response;
|
94
|
+
* **url** to remote service (optional).
|
95
|
+
|
96
|
+
You can build responses of arbitrary complexity with your own code or you can use **RenderHelper**, that comes with this
|
97
|
+
gem. Currently it supports 2 formats only: **json** and **xml**. Here is example of how to build xml response:
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
webmock_method :purchase, [:amount, :credit_card], lambda { |binding|
|
101
|
+
RenderHelper.render :xml, "#{File.dirname(__FILE__)}/templates/purchase_response.xml.erb", binding
|
102
|
+
}
|
103
|
+
```
|
104
|
+
|
105
|
+
**url** parameter is optional. If you don't specify it, it will try to use **url** attribute defined
|
106
|
+
on your service or you can define **url** parameter for WebmockMethod:
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
WebmockMethod.url = "http://api.openweathermap.org/data/2.5/weather"
|
110
|
+
```
|
111
|
+
|
112
|
+
And finally, create spec for testing your mocked service:
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
require "stubs/open_weather_map_service"
|
116
|
+
|
117
|
+
describe OpenWeatherMapService do
|
118
|
+
describe "#quote" do
|
119
|
+
it "gets the quote" do
|
120
|
+
result = JSON.parse(subject.quote("plainsboro, nj", "imperial"))
|
121
|
+
|
122
|
+
expect(result['sys']['country']).to eq("United States of America")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
```
|
127
|
+
|
128
|
+
## Contributing
|
129
|
+
|
130
|
+
1. Fork it
|
131
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
132
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
133
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
134
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path("lib", File.dirname(__FILE__))
|
4
|
+
|
5
|
+
require "rspec/core/rake_task"
|
6
|
+
require "webmock_method/version"
|
7
|
+
require "gemspec_deps_gen/gemspec_deps_gen"
|
8
|
+
|
9
|
+
version = WebmockMethod::VERSION
|
10
|
+
project_name = File.basename(Dir.pwd)
|
11
|
+
|
12
|
+
task :gen do
|
13
|
+
generator = GemspecDepsGen.new
|
14
|
+
|
15
|
+
generator.generate_dependencies "spec", "#{project_name}.gemspec.erb", "#{project_name}.gemspec"
|
16
|
+
end
|
17
|
+
|
18
|
+
task :build => :gen do
|
19
|
+
system "gem build #{project_name}.gemspec"
|
20
|
+
end
|
21
|
+
|
22
|
+
task :install do
|
23
|
+
system "gem install #{project_name}-#{version}.gem"
|
24
|
+
end
|
25
|
+
|
26
|
+
task :uninstall do
|
27
|
+
system "gem uninstall #{project_name}"
|
28
|
+
end
|
29
|
+
|
30
|
+
task :release => :build do
|
31
|
+
system "gem push #{project_name}-#{version}.gem"
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new do |task|
|
35
|
+
task.pattern = 'spec/**/*_spec.rb'
|
36
|
+
task.verbose = false
|
37
|
+
end
|
38
|
+
|
39
|
+
task :fix_debug do
|
40
|
+
system "mkdir -p $GEM_HOME/gems/debugger-ruby_core_source-1.2.3/lib"
|
41
|
+
system "cp -R ~/debugger-ruby_core_source/lib $GEM_HOME/gems/debugger-ruby_core_source-1.2.3"
|
42
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MetaMethods
|
2
|
+
extend self
|
3
|
+
|
4
|
+
def define_attribute(object, key, value)
|
5
|
+
object.singleton_class.send :attr_accessor, key.to_sym # creates accessor
|
6
|
+
|
7
|
+
object.send "#{key}=".to_sym, value # sets up value for attribute
|
8
|
+
end
|
9
|
+
|
10
|
+
def define_attributes(object, hash)
|
11
|
+
hash.each_pair do |key, value|
|
12
|
+
define_attribute(object, key, value)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module RenderHelper
|
2
|
+
extend self
|
3
|
+
|
4
|
+
def render format, template, binding
|
5
|
+
body = File.read(template)
|
6
|
+
|
7
|
+
case format
|
8
|
+
when :json
|
9
|
+
body
|
10
|
+
when :xml
|
11
|
+
ERB.new(body).result binding
|
12
|
+
else
|
13
|
+
throw "Unsupported format: #{format}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'webmock'
|
2
|
+
require 'erb'
|
3
|
+
require 'meta_methods/meta_methods'
|
4
|
+
|
5
|
+
module WebmockMethod
|
6
|
+
include MetaMethods
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_accessor :url
|
10
|
+
end
|
11
|
+
|
12
|
+
def webmock_method(method_name, param_names, response_proc, url = nil)
|
13
|
+
define_method("#{method_name}_with_webmock_method") do |*args|
|
14
|
+
param_names.each_with_index do |param_name, index|
|
15
|
+
MetaMethods.define_attribute(self, param_name, args[index])
|
16
|
+
end
|
17
|
+
|
18
|
+
yield(self, *args) if block_given?
|
19
|
+
|
20
|
+
begin
|
21
|
+
response = response_proc.call(binding)
|
22
|
+
|
23
|
+
request_url = url
|
24
|
+
request_url = @url if url.nil?
|
25
|
+
request_url = WebmockMethod.url if request_url.nil?
|
26
|
+
|
27
|
+
throw "Url is not defined." unless request_url
|
28
|
+
|
29
|
+
WebMock.stub_request(:any, request_url).to_return(:body => response)
|
30
|
+
|
31
|
+
send("#{method_name}_without_webmock_method", *args)
|
32
|
+
rescue Exception => e
|
33
|
+
puts e.message
|
34
|
+
raise e
|
35
|
+
ensure
|
36
|
+
WebMock.reset!
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
alias_method :"#{method_name}_without_webmock_method", method_name
|
41
|
+
alias_method method_name, :"#{method_name}_with_webmock_method"
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'meta_methods/meta_methods'
|
2
|
+
|
3
|
+
describe MetaMethods do
|
4
|
+
subject { MetaMethods }
|
5
|
+
|
6
|
+
describe "#define_attribute" do
|
7
|
+
it "creates new attribute on object" do
|
8
|
+
object = Object.new
|
9
|
+
|
10
|
+
subject.define_attribute object, :new_attribute, "new_attribute_value"
|
11
|
+
|
12
|
+
expect(object.new_attribute).to eq("new_attribute_value")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#define_attributes" do
|
17
|
+
it "creates new attributes on object" do
|
18
|
+
object = Object.new
|
19
|
+
|
20
|
+
subject.define_attributes object,
|
21
|
+
{new_attribute1: "new_attribute_value1",
|
22
|
+
new_attribute2: "new_attribute_value2" }
|
23
|
+
|
24
|
+
expect(object.new_attribute1).to eq("new_attribute_value1")
|
25
|
+
expect(object.new_attribute2).to eq("new_attribute_value2")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# 1. Create service
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
class OpenWeatherMapService
|
6
|
+
attr_reader :url
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@url = 'http://api.openweathermap.org/data/2.5/weather'
|
10
|
+
end
|
11
|
+
|
12
|
+
def quote location, units
|
13
|
+
quote_url = "#{url}?q=#{location}%20nj&units=#{units}"
|
14
|
+
|
15
|
+
uri = URI.parse(URI.escape(quote_url))
|
16
|
+
|
17
|
+
Net::HTTP.get(uri)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# 2. Create service mock
|
22
|
+
|
23
|
+
require 'webmock_method'
|
24
|
+
require 'json'
|
25
|
+
|
26
|
+
class OpenWeatherMapService
|
27
|
+
extend WebmockMethod
|
28
|
+
|
29
|
+
webmock_method :quote, [:location, :units], lambda { |binding|
|
30
|
+
RenderHelper.render :json, "#{File.dirname(__FILE__)}/stubs/templates/quote_response.json.erb", binding
|
31
|
+
}, /#{WebmockMethod.url}/
|
32
|
+
end
|
33
|
+
|
34
|
+
# 3. Test service mock
|
35
|
+
|
36
|
+
describe OpenWeatherMapService do
|
37
|
+
describe "#quote" do
|
38
|
+
it "gets the quote" do
|
39
|
+
result = JSON.parse(subject.quote("plainsboro, nj", "imperial"))
|
40
|
+
|
41
|
+
expect(result['sys']['country']).to eq("United States of America")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require "stubs/payment_gateway"
|
4
|
+
|
5
|
+
describe PaymentGateway do
|
6
|
+
|
7
|
+
context "#purchase" do
|
8
|
+
it "makes purchase with valid credit card" do
|
9
|
+
response = subject.purchase 1000, valid_credit_card
|
10
|
+
|
11
|
+
expect(response['success'][0]).to eq('true')
|
12
|
+
end
|
13
|
+
|
14
|
+
it "fails purchase with invalid credit card" do
|
15
|
+
response = subject.purchase 1000, invalid_credit_card
|
16
|
+
|
17
|
+
expect(response['success'][0]).to eq('false')
|
18
|
+
expect(response['error_message'][0]).to eq('Unsupported Credit Card Type')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def valid_credit_card
|
25
|
+
stub(
|
26
|
+
:first_name => "John",
|
27
|
+
last_name: "Appleseed",
|
28
|
+
number: "4242424242424242",
|
29
|
+
card_type: "VISA",
|
30
|
+
month: 8,
|
31
|
+
year: Time.now.year+1,
|
32
|
+
verification_value: "000"
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
def invalid_credit_card
|
37
|
+
invalid_credit_card = valid_credit_card
|
38
|
+
|
39
|
+
invalid_credit_card.stubs(:card_type => "DISCOVER")
|
40
|
+
|
41
|
+
invalid_credit_card
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'xmlsimple'
|
3
|
+
|
4
|
+
class PaymentGateway
|
5
|
+
attr_reader :url
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@url = 'http://www.paymentgateway.com/api/'
|
9
|
+
end
|
10
|
+
|
11
|
+
def purchase amount, credit_card
|
12
|
+
body = build_body File.dirname(__FILE__) + "/templates/purchase_request.xml.erb", binding
|
13
|
+
|
14
|
+
response = soap_post "purchase", body
|
15
|
+
|
16
|
+
response_body_to_hash response.body
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def build_body request_file_name, binding
|
22
|
+
erb = ERB.new(request_file_name)
|
23
|
+
|
24
|
+
erb.result binding
|
25
|
+
end
|
26
|
+
|
27
|
+
def soap_post action, body
|
28
|
+
uri = URI.parse(URI.escape(@url))
|
29
|
+
|
30
|
+
headers = {}
|
31
|
+
headers["User-Agent"] = "Ruby/#{RUBY_VERSION}"
|
32
|
+
headers["SOAPAction"] = action
|
33
|
+
headers["Content-Type"] = "text/xml;charset=UTF-8"
|
34
|
+
|
35
|
+
connection = Net::HTTP.new(uri.host, uri.port)
|
36
|
+
|
37
|
+
request = Net::HTTP::Post.new(uri.request_uri, headers)
|
38
|
+
|
39
|
+
request.body = body
|
40
|
+
|
41
|
+
connection.request(request)
|
42
|
+
end
|
43
|
+
|
44
|
+
def response_body_to_hash body
|
45
|
+
result = XmlSimple.xml_in(body)
|
46
|
+
|
47
|
+
Hash[ result.collect {|k,v| [underscore(k), v] } ]
|
48
|
+
end
|
49
|
+
|
50
|
+
def underscore(camel_cased_word)
|
51
|
+
camel_cased_word.to_s.gsub(/::/, '/').
|
52
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
53
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
54
|
+
tr("-", "_").
|
55
|
+
downcase
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<PurchaseRequest>
|
2
|
+
<CreditCard>
|
3
|
+
<FirstName><%= credit_card.first_name %></FirstName>
|
4
|
+
<LastName><%= credit_card.last_name %></LastName>
|
5
|
+
<CardType><%= credit_card.type %></CardType>
|
6
|
+
<Number><%= credit_card.number %></Number>
|
7
|
+
<Month><%= credit_card.month %></Month>
|
8
|
+
<Year><%= credit_card.year %></Year>
|
9
|
+
<VerifiactionValue><%= credit_card.verification_value %></VerifiactionValue>
|
10
|
+
</CreditCard>
|
11
|
+
|
12
|
+
<Amount><%= amount %></Amount>
|
13
|
+
</PurchaseRequest>
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'webmock_method'
|
2
|
+
|
3
|
+
require "services/payment_gateway.rb"
|
4
|
+
|
5
|
+
class PaymentGateway
|
6
|
+
extend WebmockMethod
|
7
|
+
|
8
|
+
webmock_method :purchase, [:amount, :credit_card], lambda { |binding|
|
9
|
+
RenderHelper.render :xml, "#{File.dirname(__FILE__)}/templates/purchase_response.xml.erb", binding
|
10
|
+
} do |parent, _, credit_card|
|
11
|
+
if credit_card.card_type == "VISA"
|
12
|
+
define_attribute(parent, :success, true)
|
13
|
+
else
|
14
|
+
define_attribute(parent, :success, false)
|
15
|
+
define_attribute(parent, :error_message, "Unsupported Credit Card Type")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
{
|
2
|
+
"coord": {
|
3
|
+
"lon": -74.626356353983,
|
4
|
+
"lat": 40.339083485305
|
5
|
+
},
|
6
|
+
"sys": {
|
7
|
+
"country": "United States of America",
|
8
|
+
"sunrise": 1382440672,
|
9
|
+
"sunset": 1382479669
|
10
|
+
},
|
11
|
+
"weather": [
|
12
|
+
{
|
13
|
+
"id": 800,
|
14
|
+
"main": "Clear",
|
15
|
+
"description": "Sky is Clear",
|
16
|
+
"icon": "01n"
|
17
|
+
}
|
18
|
+
],
|
19
|
+
"base": "global stations",
|
20
|
+
"main": {
|
21
|
+
"temp": 53.74,
|
22
|
+
"humidity": 66,
|
23
|
+
"pressure": 1008.259,
|
24
|
+
"temp_min": 51.8,
|
25
|
+
"temp_max": 56.48
|
26
|
+
},
|
27
|
+
"wind": {
|
28
|
+
"speed": 6.39,
|
29
|
+
"deg": 185.002
|
30
|
+
},
|
31
|
+
"clouds": {
|
32
|
+
"all": 0
|
33
|
+
},
|
34
|
+
"dt": 1382403463,
|
35
|
+
"id": 5102940,
|
36
|
+
"name": "Plainsboro Twp",
|
37
|
+
"cod": 200
|
38
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/lib/webmock_method/version')
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "webmock_method"
|
7
|
+
spec.summary = %q{Extension for webmock to make stubbed methods.}
|
8
|
+
spec.description = %q{Extension for webmock to make stubbed methods.}
|
9
|
+
spec.email = "alexander.shvets@gmail.com"
|
10
|
+
spec.authors = ["Alexander Shvets"]
|
11
|
+
spec.homepage = "http://github.com/shvets/webmock_method"
|
12
|
+
|
13
|
+
spec.files = `git ls-files`.split($\)
|
14
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
|
+
spec.require_paths = ["lib"]
|
16
|
+
spec.version = WebmockMethod::VERSION
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
<%= project_dependencies %>
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webmock_method
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Shvets
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: webmock
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: gemspec_deps_gen
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: gemcutter
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Extension for webmock to make stubbed methods.
|
56
|
+
email: alexander.shvets@gmail.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- .gitignore
|
62
|
+
- .idea/.name
|
63
|
+
- .idea/.rakeTasks
|
64
|
+
- .idea/encodings.xml
|
65
|
+
- .idea/jenkinsSettings.xml
|
66
|
+
- .idea/misc.xml
|
67
|
+
- .idea/modules.xml
|
68
|
+
- .idea/scopes/scope_settings.xml
|
69
|
+
- .idea/vcs.xml
|
70
|
+
- .idea/webmock_method.iml
|
71
|
+
- .ruby-gemset
|
72
|
+
- .ruby-version
|
73
|
+
- CHANGES
|
74
|
+
- Gemfile
|
75
|
+
- LICENSE
|
76
|
+
- LICENSE.txt
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- lib/meta_methods/meta_methods.rb
|
80
|
+
- lib/webmock_method.rb
|
81
|
+
- lib/webmock_method/render_helper.rb
|
82
|
+
- lib/webmock_method/version.rb
|
83
|
+
- lib/webmock_method/webmock_method.rb
|
84
|
+
- spec/meta_methods_spec.rb
|
85
|
+
- spec/open_weather_map_service_spec.rb
|
86
|
+
- spec/payment_gateway_spec.rb
|
87
|
+
- spec/services/payment_gateway.rb
|
88
|
+
- spec/services/templates/purchase_request.xml.erb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
- spec/stubs/payment_gateway.rb
|
91
|
+
- spec/stubs/templates/purchase_response.xml.erb
|
92
|
+
- spec/stubs/templates/quote_response.json.erb
|
93
|
+
- webmock_method.gemspec.erb
|
94
|
+
homepage: http://github.com/shvets/webmock_method
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.0.7
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: Extension for webmock to make stubbed methods.
|
118
|
+
test_files:
|
119
|
+
- spec/meta_methods_spec.rb
|
120
|
+
- spec/open_weather_map_service_spec.rb
|
121
|
+
- spec/payment_gateway_spec.rb
|
122
|
+
- spec/services/payment_gateway.rb
|
123
|
+
- spec/services/templates/purchase_request.xml.erb
|
124
|
+
- spec/spec_helper.rb
|
125
|
+
- spec/stubs/payment_gateway.rb
|
126
|
+
- spec/stubs/templates/purchase_response.xml.erb
|
127
|
+
- spec/stubs/templates/quote_response.json.erb
|