brightbox-rspec-rails-ext 1.1.0 → 1.003
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/CHANGELOG +1 -4
- data/Manifest +0 -2
- data/README.rdoc +20 -25
- data/Rakefile +3 -8
- data/rspec-rails-ext.gemspec +6 -6
- metadata +4 -7
- data/lib/mocks.rb +0 -27
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
data/README.rdoc
CHANGED
|
@@ -6,44 +6,39 @@ Some prettifications for RSpec Rails.
|
|
|
6
6
|
|
|
7
7
|
sudo gem install brightbox-rspec-rails-ext --source=http://gems.github.com/
|
|
8
8
|
|
|
9
|
-
Then, within your
|
|
9
|
+
Then, within your config/environment.rb:
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
config.gem 'brightbox-rspec-rails-ext', :lib => 'rspec_rails_extensions', :source => 'http://gems.github.com'
|
|
12
12
|
|
|
13
13
|
== ActiveRecord::RecordInvalid
|
|
14
14
|
|
|
15
15
|
If you try to call ActiveRecord::RecordInvalid.new(@my_object) where @my_object is a mock then your exception will not be raised; instead you get a cryptic error. This is because RecordInvalid expects to be able to call certain methods on your ActiveRecord model, which your mock isn't set up for. So instead, prepare your mock, like so:
|
|
16
16
|
|
|
17
|
-
@thingy = mock_model Thingy
|
|
17
|
+
@thingy = mock_model Thingy
|
|
18
18
|
prepare_for_errors_on @thingy
|
|
19
19
|
raise ActiveRecord::RecordInvalid.new(@thingy)
|
|
20
|
-
|
|
21
|
-
There's also a short-cut method:
|
|
22
|
-
|
|
23
|
-
@thingy = invalid_model Thingy, :field => 'value'
|
|
24
|
-
raise ActiveRecord::RecordInvalid.new(@thingy)
|
|
25
20
|
|
|
26
21
|
== Matchers
|
|
27
22
|
|
|
28
23
|
Some helpful matchers for testing HTTP statuses beyond the default be_success (200 OK)
|
|
29
24
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
25
|
+
# looks for a 201 Created (useful for API CREATE calls)
|
|
26
|
+
response.should be_successfully_created
|
|
27
|
+
|
|
28
|
+
# expects a Location field with the given URL (useful for API CREATE calls)
|
|
29
|
+
response.should point_to(url)
|
|
30
|
+
|
|
31
|
+
# looks for a 422 response (invalid object)
|
|
32
|
+
response.should be_unprocessable
|
|
33
|
+
|
|
34
|
+
# looks for a 404
|
|
35
|
+
response.should be_not_found
|
|
36
|
+
|
|
37
|
+
# looks for a 401
|
|
38
|
+
response.should be_unauthorised
|
|
39
|
+
|
|
40
|
+
# looks for a 500
|
|
41
|
+
response.should be_an_error
|
|
47
42
|
|
|
48
43
|
== Specifying your controllers
|
|
49
44
|
|
data/Rakefile
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
require 'echoe'
|
|
2
2
|
Echoe.new('rspec-rails-ext') do | gem |
|
|
3
|
-
gem.author = 'Rahoul Baruah
|
|
3
|
+
gem.author = 'Rahoul Baruah'
|
|
4
4
|
gem.email = 'support@brightbox.co.uk'
|
|
5
5
|
gem.summary = 'Helpers for prettying up your RSpec-Rails specifications'
|
|
6
|
-
gem.url = 'http://github.com/brightbox
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
desc "Generates the manifest and the gemspec"
|
|
10
|
-
task :build => [:manifest, :build_gemspec] do
|
|
11
|
-
puts "Built!"
|
|
12
|
-
end
|
|
6
|
+
gem.url = 'http://github.com/brightbox-rspec-rails-ext'
|
|
7
|
+
end
|
data/rspec-rails-ext.gemspec
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
4
|
s.name = %q{rspec-rails-ext}
|
|
5
|
-
s.version = "1.
|
|
5
|
+
s.version = "1.003"
|
|
6
6
|
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
|
8
|
-
s.authors = ["Rahoul Baruah
|
|
9
|
-
s.date = %q{2009-02-
|
|
8
|
+
s.authors = ["Rahoul Baruah"]
|
|
9
|
+
s.date = %q{2009-02-13}
|
|
10
10
|
s.description = %q{Helpers for prettying up your RSpec-Rails specifications}
|
|
11
11
|
s.email = %q{support@brightbox.co.uk}
|
|
12
|
-
s.extra_rdoc_files = ["CHANGELOG", "lib/controller_example_group.rb", "lib/
|
|
13
|
-
s.files = ["CHANGELOG", "lib/controller_example_group.rb", "lib/
|
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "lib/controller_example_group.rb", "lib/responses.rb", "lib/rspec_rails_extensions.rb", "README.rdoc"]
|
|
13
|
+
s.files = ["CHANGELOG", "lib/controller_example_group.rb", "lib/responses.rb", "lib/rspec_rails_extensions.rb", "LICENCE", "Manifest", "Rakefile", "README.rdoc", "rspec-rails-ext.gemspec"]
|
|
14
14
|
s.has_rdoc = true
|
|
15
|
-
s.homepage = %q{http://github.com/brightbox
|
|
15
|
+
s.homepage = %q{http://github.com/brightbox-rspec-rails-ext}
|
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rspec-rails-ext", "--main", "README.rdoc"]
|
|
17
17
|
s.require_paths = ["lib"]
|
|
18
18
|
s.rubyforge_project = %q{rspec-rails-ext}
|
metadata
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: brightbox-rspec-rails-ext
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: "1.003"
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
- Rahoul Baruah
|
|
7
|
+
- Rahoul Baruah
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-02-
|
|
12
|
+
date: 2009-02-13 00:00:00 -08:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: echoe
|
|
17
|
-
type: :development
|
|
18
17
|
version_requirement:
|
|
19
18
|
version_requirements: !ruby/object:Gem::Requirement
|
|
20
19
|
requirements:
|
|
@@ -31,14 +30,12 @@ extensions: []
|
|
|
31
30
|
extra_rdoc_files:
|
|
32
31
|
- CHANGELOG
|
|
33
32
|
- lib/controller_example_group.rb
|
|
34
|
-
- lib/mocks.rb
|
|
35
33
|
- lib/responses.rb
|
|
36
34
|
- lib/rspec_rails_extensions.rb
|
|
37
35
|
- README.rdoc
|
|
38
36
|
files:
|
|
39
37
|
- CHANGELOG
|
|
40
38
|
- lib/controller_example_group.rb
|
|
41
|
-
- lib/mocks.rb
|
|
42
39
|
- lib/responses.rb
|
|
43
40
|
- lib/rspec_rails_extensions.rb
|
|
44
41
|
- LICENCE
|
|
@@ -47,7 +44,7 @@ files:
|
|
|
47
44
|
- README.rdoc
|
|
48
45
|
- rspec-rails-ext.gemspec
|
|
49
46
|
has_rdoc: true
|
|
50
|
-
homepage: http://github.com/brightbox
|
|
47
|
+
homepage: http://github.com/brightbox-rspec-rails-ext
|
|
51
48
|
post_install_message:
|
|
52
49
|
rdoc_options:
|
|
53
50
|
- --line-numbers
|
data/lib/mocks.rb
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
module Spec
|
|
2
|
-
module Rails
|
|
3
|
-
module Mocks
|
|
4
|
-
# Set up the given mock model in preparation for an ActiveRecord::RecordInvalid call
|
|
5
|
-
# For example:
|
|
6
|
-
# @user = mock_model User
|
|
7
|
-
# prepare_for_errors_on @user
|
|
8
|
-
# @user.should_receive(:save!).and_raise(ActiveRecord::RecordInvalid.new(@user))
|
|
9
|
-
# If you tried this without the call to prepare_for_errors_on, the RecordInvalid exception would not be raised.
|
|
10
|
-
def prepare_for_errors_on model
|
|
11
|
-
errors = mock 'errors'
|
|
12
|
-
errors.should_receive(:full_messages).and_return([])
|
|
13
|
-
model.should_receive(:errors).and_return(errors)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# Shortcut to create a mock model that is prepared for a ActiveRecord::RecordInvalid.new(@model) call
|
|
17
|
-
# Equivalent to:
|
|
18
|
-
# @model = mock_model Model, :some => :fields
|
|
19
|
-
# prepare_for_errors_on @model
|
|
20
|
-
def invalid_model class_name, stubs = {}
|
|
21
|
-
model = mock_model class_name, stubs
|
|
22
|
-
prepare_for_errors_on model
|
|
23
|
-
return model
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|