fakettp 0.2.4.1 → 0.3.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 (41) hide show
  1. data/.gitignore +6 -0
  2. data/README.rdoc +201 -0
  3. data/Rakefile +113 -0
  4. data/VERSION +1 -0
  5. data/features/control.feature +12 -0
  6. data/features/dashboard.feature +38 -0
  7. data/features/expectations.feature +27 -0
  8. data/features/expectations/expect_get +3 -0
  9. data/features/expectations/get_foo +3 -0
  10. data/features/expectations/get_root +3 -0
  11. data/features/expectations/pass_and_fail +5 -0
  12. data/features/expectations/set_response +5 -0
  13. data/features/step_definitions/expectations.rb +5 -0
  14. data/features/step_definitions/http.rb +42 -0
  15. data/features/step_definitions/simulator.rb +25 -0
  16. data/features/step_definitions/webrat_steps.rb +99 -0
  17. data/features/support/env.rb +5 -0
  18. data/features/support/fakettp.rb +2 -0
  19. data/features/support/paths.rb +12 -0
  20. data/features/support/xpath.rb +10 -0
  21. data/features/verification.feature +49 -0
  22. data/lib/fakettp/commands/fakettp_command.rb +31 -19
  23. data/lib/fakettp/controller.rb +12 -0
  24. data/lib/fakettp/db.rb +7 -0
  25. data/lib/fakettp/error.rb +6 -18
  26. data/lib/fakettp/expectation.rb +28 -44
  27. data/lib/fakettp/fakettp.yml +3 -0
  28. data/lib/fakettp/public/fakettp.css +33 -0
  29. data/lib/fakettp/schema.rb +14 -0
  30. data/lib/fakettp/simulator.rb +16 -10
  31. data/lib/fakettp/views/index.erb +14 -0
  32. data/spec/fakettp/commands/fakettp_command_spec.rb +128 -0
  33. data/spec/fakettp/controller_spec.rb +250 -0
  34. data/spec/fakettp/error_spec.rb +40 -0
  35. data/spec/fakettp/expectation_helper_spec.rb +33 -0
  36. data/spec/fakettp/expectation_spec.rb +142 -0
  37. data/spec/fakettp/simulator_spec.rb +149 -0
  38. data/spec/spec.opts +1 -0
  39. data/spec/spec_helper.rb +18 -0
  40. metadata +73 -24
  41. data/README.html +0 -113
@@ -0,0 +1,40 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Fakettp::Error do
4
+ before do
5
+ Fakettp::Error.delete_all
6
+ end
7
+
8
+ it 'is an ActiveRecord' do
9
+ Fakettp::Error.new.should be_a_kind_of(ActiveRecord::Base)
10
+ end
11
+
12
+ it { should have_db_column(:message).of_type(:text) }
13
+
14
+ it { should have_db_column(:line_number).of_type(:integer) }
15
+
16
+ it { should belong_to(:expectation) }
17
+
18
+ describe 'listing errors' do
19
+ describe 'when errors exist' do
20
+ before do
21
+ Fakettp::Error.create! :message => 'foo'
22
+ Fakettp::Error.create! :message => 'bar'
23
+ end
24
+
25
+ it 'returns the concatenated error messages' do
26
+ Fakettp::Error.list.should == "foo\nbar\n"
27
+ end
28
+ end
29
+
30
+ describe 'when no errors exist' do
31
+ before do
32
+ Fakettp::Error.delete_all
33
+ end
34
+
35
+ it 'returns an empty string' do
36
+ Fakettp::Error.list.should == ''
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Fakettp::ExpectationHelper do
4
+ it 'mixes in Spec::Matchers' do
5
+ class Foo
6
+ include Fakettp::ExpectationHelper
7
+ end
8
+
9
+ Foo.included_modules.should include(Spec::Matchers)
10
+ end
11
+
12
+ describe 'calling expect' do
13
+ describe 'when a matcher exception occurs' do
14
+ it 'raises an exception' do
15
+ lambda {
16
+ Fakettp::ExpectationHelper.expect 'foo' do
17
+ 1.should == 2
18
+ end
19
+ }.should raise_error(Fakettp::Expectation::Error,
20
+ /Error in foo: expected: 2,\s*got: 1/)
21
+ end
22
+ end
23
+
24
+ describe 'when the block returns a value' do
25
+ it 'returns the value' do
26
+ result = Fakettp::ExpectationHelper.expect 'foo' do
27
+ 'bar'
28
+ end
29
+ result.should == 'bar'
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,142 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Fakettp::Expectation do
4
+ before do
5
+ Fakettp::Expectation.delete_all
6
+ end
7
+
8
+ it 'is an ActiveRecord' do
9
+ Fakettp::Expectation.new.should be_a_kind_of(ActiveRecord::Base)
10
+ end
11
+
12
+ it { should have_db_column(:contents).of_type(:text) }
13
+
14
+ it { should have_db_column(:executed).of_type(:boolean) }
15
+
16
+ it { should have_many(:errors) }
17
+
18
+ it 'starts out unexecuted' do
19
+ Fakettp::Expectation.create.executed.should be_false
20
+ end
21
+
22
+ describe 'checking whether all expected requests have been received' do
23
+ describe 'when there are no expectations' do
24
+ before do
25
+ Fakettp::Expectation.delete_all
26
+ end
27
+
28
+ it 'returns true' do
29
+ Fakettp::Expectation.should be_all_received
30
+ end
31
+ end
32
+
33
+ describe "when there are expectations that haven't been run" do
34
+ before do
35
+ Fakettp::Expectation.create! :executed => true
36
+ Fakettp::Expectation.create! :executed => false
37
+ end
38
+
39
+ it 'returns false' do
40
+ Fakettp::Expectation.should_not be_all_received
41
+ end
42
+ end
43
+
44
+ describe "when all expectations have been run" do
45
+ before do
46
+ Fakettp::Expectation.create! :executed => true
47
+ Fakettp::Expectation.create! :executed => true
48
+ end
49
+
50
+ it 'returns true' do
51
+ Fakettp::Expectation.should be_all_received
52
+ end
53
+ end
54
+ end
55
+
56
+ describe 'getting the next expectation' do
57
+ describe 'when there are expectations' do
58
+ before do
59
+ @expectation_1 = Fakettp::Expectation.create :executed => true
60
+ @expectation_2 = Fakettp::Expectation.create :executed => false
61
+ @expectation_3 = Fakettp::Expectation.create :executed => false
62
+ end
63
+
64
+ it 'returns the first unexecuted expectation' do
65
+ Fakettp::Expectation.next.should == @expectation_2
66
+ end
67
+ end
68
+
69
+ describe 'when there are no expectations' do
70
+ before do
71
+ Fakettp::Expectation.delete_all
72
+ end
73
+
74
+ it 'returns nil' do
75
+ Fakettp::Expectation.next.should be_nil
76
+ end
77
+ end
78
+ end
79
+
80
+ describe 'rendering itself' do
81
+ before do
82
+ @expectation = Fakettp::Expectation.new(:contents => 'foo')
83
+ end
84
+
85
+ describe 'when not executed' do
86
+ it 'shows its contents' do
87
+ @expectation.render.should == 'foo'
88
+ end
89
+ end
90
+
91
+ describe 'when executed successfully' do
92
+ before do
93
+ @expectation.executed = true
94
+ end
95
+
96
+ it %(shows its contents in a 'pass' span) do
97
+ @expectation.render.should == '<span class="pass">foo</span>'
98
+ end
99
+ end
100
+
101
+ describe 'when executed with errors' do
102
+ before do
103
+ @expectation.executed = true
104
+ @expectation.errors = [Fakettp::Error.new]
105
+ end
106
+
107
+ it %(shows its contents in a 'fail' span) do
108
+ @expectation.render.should == '<span class="fail">foo</span>'
109
+ end
110
+ end
111
+ end
112
+
113
+ describe 'executing' do
114
+ it 'evals the expectation code in the context of the supplied binding' do
115
+ def getBinding(n)
116
+ return binding
117
+ end
118
+ Fakettp::Expectation.new(:contents => 'n + 2').execute(getBinding(2)).should == 4
119
+ end
120
+
121
+ it 'marks itself as executed' do
122
+ expectation = Fakettp::Expectation.create! :contents => ''
123
+ expectation.execute binding
124
+ expectation.reload
125
+ expectation.executed.should be_true
126
+ end
127
+ end
128
+ end
129
+
130
+ describe Fakettp::Expectation::Error do
131
+ it 'stores a message' do
132
+ Fakettp::Expectation::Error.new('foo', 2).message.should == 'foo'
133
+ end
134
+
135
+ it 'stores a line number' do
136
+ Fakettp::Expectation::Error.new('foo', 2).line_number.should == 2
137
+ end
138
+
139
+ it 'defaults the line number to nil' do
140
+ Fakettp::Expectation::Error.new('foo').line_number.should be_nil
141
+ end
142
+ end
@@ -0,0 +1,149 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Fakettp::Simulator do
4
+ before do
5
+ Fakettp::Expectation.stub! :delete_all
6
+ Fakettp::Error.stub! :delete_all
7
+ end
8
+
9
+ describe "resetting" do
10
+ def do_reset
11
+ Fakettp::Simulator.reset
12
+ end
13
+
14
+ it 'clears expectations' do
15
+ Fakettp::Expectation.should_receive :delete_all
16
+ do_reset
17
+ end
18
+
19
+ it 'clears errors' do
20
+ Fakettp::Error.should_receive :delete_all
21
+ do_reset
22
+ end
23
+ end
24
+
25
+ describe 'adding an expectation' do
26
+ before do
27
+ @expectation = stub(:expectation)
28
+ end
29
+
30
+ def do_add
31
+ Fakettp::Simulator << @expectation
32
+ end
33
+
34
+ it 'creates a new expectation' do
35
+ Fakettp::Expectation.should_receive(:create!).with :contents => @expectation
36
+ do_add
37
+ end
38
+ end
39
+
40
+ describe 'handling a request' do
41
+ before do
42
+ @binding = stub :binding
43
+ @result = 'foo'
44
+ @expectation = mock Fakettp::Expectation, :execute => @result
45
+ Fakettp::Expectation.stub!(:next).and_return @expectation
46
+ end
47
+
48
+ def do_handle
49
+ Fakettp::Simulator.handle_request @binding
50
+ end
51
+
52
+ it 'executes the next request' do
53
+ @expectation.should_receive(:execute).with @binding
54
+ do_handle
55
+ end
56
+
57
+ it 'returns the execution result' do
58
+ do_handle.should == @result
59
+ end
60
+
61
+ describe 'when there are no expectations left' do
62
+ before do
63
+ Fakettp::Expectation.stub!(:next).and_return nil
64
+ end
65
+
66
+ it 'adds an error' do
67
+ Fakettp::Error.should_receive(:create!).with(:message => 'Received unexpected request')
68
+ begin
69
+ do_handle
70
+ rescue Fakettp::Expectation::Error;end
71
+ end
72
+
73
+ it 'raises an exception' do
74
+ lambda {do_handle}.should raise_error(Fakettp::Expectation::Error, 'Received unexpected request')
75
+ end
76
+ end
77
+
78
+ describe 'when an error occurs while executing the expectation' do
79
+ before do
80
+ @expectation.stub!(:execute).and_raise Fakettp::Expectation::Error.new('foo', 2)
81
+ @errors = stub :errors, :null_object => true
82
+ @expectation.stub!(:errors).and_return @errors
83
+ end
84
+
85
+ it 'adds an error to the expectation' do
86
+ @errors.should_receive(:create).with(:message => 'foo', :line_number => 2)
87
+ begin
88
+ do_handle
89
+ rescue Fakettp::Expectation::Error;end
90
+ end
91
+
92
+ it 're-raises the exception' do
93
+ lambda {do_handle}.should raise_error(Fakettp::Expectation::Error, 'foo')
94
+ end
95
+ end
96
+ end
97
+
98
+ describe "verifying" do
99
+ def do_verify
100
+ Fakettp::Simulator.verify
101
+ end
102
+
103
+ describe 'when there are pending expectations' do
104
+ before do
105
+ Fakettp::Expectation.stub!(:all_received?).and_return true
106
+ end
107
+
108
+ describe 'when there are no errors' do
109
+ before do
110
+ Fakettp::Error.stub!(:exists?).with(no_args).and_return false
111
+ end
112
+
113
+ it { do_verify.should be_true }
114
+ end
115
+
116
+ describe 'when there are errors' do
117
+ before do
118
+ Fakettp::Error.stub!(:exists?).with(no_args).and_return true
119
+ end
120
+
121
+ it { do_verify.should be_false }
122
+ end
123
+ end
124
+
125
+ describe 'when there are pending expectations' do
126
+ before do
127
+ Fakettp::Expectation.stub!(:all_received?).and_return false
128
+ end
129
+
130
+ it 'adds an error' do
131
+ Fakettp::Error.should_receive(:create!).with(:message => 'Expected request not received')
132
+ do_verify
133
+ end
134
+
135
+ it { do_verify.should be_false }
136
+ end
137
+ end
138
+
139
+ describe 'listing errors' do
140
+ before do
141
+ @errors = stub :errors
142
+ Fakettp::Error.stub!(:list).and_return @errors
143
+ end
144
+
145
+ it 'returns the error list' do
146
+ Fakettp::Simulator.list_errors.should == @errors
147
+ end
148
+ end
149
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'sinatra'
4
+ require 'spec/interop/test'
5
+ require 'sinatra/test'
6
+ require 'active_record'
7
+ require 'shoulda/active_record'
8
+
9
+ set :environment, :test
10
+
11
+ $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib/fakettp'))
12
+
13
+ FAKETTP_BASE = File.join(File.dirname(__FILE__), '..', 'tmp', 'install')
14
+ FileUtils.rm_rf FAKETTP_BASE
15
+ require 'fakettp/commands/fakettp_command'
16
+ Fakettp::Commands::FakettpCommand.new(['install', FAKETTP_BASE, 'fakettp.local']).run
17
+
18
+ require 'fakettp'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakettp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kerry Buckley
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-13 00:00:00 +01:00
12
+ date: 2009-10-19 00:00:00 +01:00
13
13
  default_executable: fakettp
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,74 +20,117 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.9.1.3
23
+ version: "0"
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
- name: rspec
26
+ name: sqlite3-ruby
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: jeweler
27
37
  type: :development
28
38
  version_requirement:
29
39
  version_requirements: !ruby/object:Gem::Requirement
30
40
  requirements:
31
41
  - - ">="
32
42
  - !ruby/object:Gem::Version
33
- version: 1.1.12
43
+ version: "0"
34
44
  version:
35
45
  - !ruby/object:Gem::Dependency
36
- name: spicycode-rcov
46
+ name: rcov
37
47
  type: :development
38
48
  version_requirement:
39
49
  version_requirements: !ruby/object:Gem::Requirement
40
50
  requirements:
41
51
  - - ">="
42
52
  - !ruby/object:Gem::Version
43
- version: 0.8.0
53
+ version: "0"
44
54
  version:
45
55
  - !ruby/object:Gem::Dependency
46
- name: cucumber
56
+ name: rspec
47
57
  type: :development
48
58
  version_requirement:
49
59
  version_requirements: !ruby/object:Gem::Requirement
50
60
  requirements:
51
61
  - - ">="
52
62
  - !ruby/object:Gem::Version
53
- version: 0.1.16
63
+ version: "0"
54
64
  version:
55
65
  - !ruby/object:Gem::Dependency
56
- name: RedCloth
66
+ name: cucumber
57
67
  type: :development
58
68
  version_requirement:
59
69
  version_requirements: !ruby/object:Gem::Requirement
60
70
  requirements:
61
71
  - - ">="
62
72
  - !ruby/object:Gem::Version
63
- version: 4.1.1
73
+ version: "0"
64
74
  version:
65
- description:
75
+ description: HTTP server mocking tool
66
76
  email: kerryjbuckley@gmail.com
67
77
  executables:
68
78
  - fakettp
69
79
  extensions: []
70
80
 
71
- extra_rdoc_files: []
72
-
81
+ extra_rdoc_files:
82
+ - README.rdoc
73
83
  files:
84
+ - .gitignore
85
+ - README.rdoc
86
+ - Rakefile
87
+ - VERSION
88
+ - bin/fakettp
89
+ - features/control.feature
90
+ - features/dashboard.feature
91
+ - features/expectations.feature
92
+ - features/expectations/expect_get
93
+ - features/expectations/get_foo
94
+ - features/expectations/get_root
95
+ - features/expectations/pass_and_fail
96
+ - features/expectations/set_response
97
+ - features/step_definitions/expectations.rb
98
+ - features/step_definitions/http.rb
99
+ - features/step_definitions/simulator.rb
100
+ - features/step_definitions/webrat_steps.rb
101
+ - features/support/env.rb
102
+ - features/support/fakettp.rb
103
+ - features/support/paths.rb
104
+ - features/support/xpath.rb
105
+ - features/verification.feature
106
+ - lib/fakettp.rb
74
107
  - lib/fakettp/commands/fakettp_command.rb
75
108
  - lib/fakettp/config.ru
76
109
  - lib/fakettp/controller.rb
110
+ - lib/fakettp/db.rb
77
111
  - lib/fakettp/error.rb
78
112
  - lib/fakettp/expectation.rb
79
113
  - lib/fakettp/expectation_helper.rb
114
+ - lib/fakettp/fakettp.yml
115
+ - lib/fakettp/public/fakettp.css
116
+ - lib/fakettp/schema.rb
80
117
  - lib/fakettp/simulator.rb
81
- - lib/fakettp.rb
82
- - bin/fakettp
83
- - README.html
118
+ - lib/fakettp/views/index.erb
119
+ - spec/fakettp/commands/fakettp_command_spec.rb
120
+ - spec/fakettp/controller_spec.rb
121
+ - spec/fakettp/error_spec.rb
122
+ - spec/fakettp/expectation_helper_spec.rb
123
+ - spec/fakettp/expectation_spec.rb
124
+ - spec/fakettp/simulator_spec.rb
125
+ - spec/spec.opts
126
+ - spec/spec_helper.rb
84
127
  has_rdoc: true
85
- homepage: http://github.com/kerryb/fakettp/
128
+ homepage: http://github.com/kerryb/fakettp
86
129
  licenses: []
87
130
 
88
131
  post_install_message:
89
- rdoc_options: []
90
-
132
+ rdoc_options:
133
+ - --charset=UTF-8
91
134
  require_paths:
92
135
  - lib
93
136
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -104,10 +147,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
147
  version:
105
148
  requirements: []
106
149
 
107
- rubyforge_project: fakettp
108
- rubygems_version: 1.3.2
150
+ rubyforge_project:
151
+ rubygems_version: 1.3.5
109
152
  signing_key:
110
153
  specification_version: 3
111
154
  summary: HTTP server mocking tool
112
- test_files: []
113
-
155
+ test_files:
156
+ - spec/fakettp/commands/fakettp_command_spec.rb
157
+ - spec/fakettp/controller_spec.rb
158
+ - spec/fakettp/error_spec.rb
159
+ - spec/fakettp/expectation_helper_spec.rb
160
+ - spec/fakettp/expectation_spec.rb
161
+ - spec/fakettp/simulator_spec.rb
162
+ - spec/spec_helper.rb