brightbox-rspec-rails-ext 1.0 → 1.0.6

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 CHANGED
@@ -1 +1,7 @@
1
- v1.0. Initial release
1
+ v1.0.6. Bug fixes
2
+ v1.0.5. Added invalid_model
3
+ v1.0.4. Added `rake build`
4
+ v1.0.3. Added mocks - prepare_for_errors_on
5
+ v1.0.2. Bugfix
6
+ v1.0.1. Bugfix
7
+ v1.0.0. Initial release
data/Manifest CHANGED
@@ -1,8 +1,10 @@
1
1
  CHANGELOG
2
2
  lib/controller_example_group.rb
3
+ lib/mocks.rb
3
4
  lib/responses.rb
4
5
  lib/rspec_rails_extensions.rb
5
6
  LICENCE
6
7
  Manifest
7
8
  Rakefile
8
9
  README.rdoc
10
+ rspec-rails-ext.gemspec
data/README.rdoc CHANGED
@@ -6,31 +6,44 @@ 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 config/environment.rb:
9
+ Then, within your spec/spec_helper.rb
10
10
 
11
- config.gem 'brightbox-rspec-rails-ext', :lib => 'rspec_rails_extensions', :source => 'http://gems.github.com'
11
+ require 'rspec_rails_extensions'
12
+
13
+ == ActiveRecord::RecordInvalid
14
+
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
+
17
+ @thingy = mock_model Thingy, :field => 'value'
18
+ prepare_for_errors_on @thingy
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)
12
25
 
13
26
  == Matchers
14
27
 
15
28
  Some helpful matchers for testing HTTP statuses beyond the default be_success (200 OK)
16
29
 
17
- # looks for a 201 Created (useful for API CREATE calls)
18
- response.should be_successfully_created
19
-
20
- # expects a Location field with the given URL (useful for API CREATE calls)
21
- response.should point_to(url)
22
-
23
- # looks for a 422 response (invalid object)
24
- response.should be_unprocessable
25
-
26
- # looks for a 404
27
- response.should be_not_found
28
-
29
- # looks for a 401
30
- response.should be_unauthorised
31
-
32
- # looks for a 500
33
- response.should be_an_error
30
+ # looks for a 201 Created (useful for API CREATE calls)
31
+ response.should be_successfully_created
32
+
33
+ # expects a Location field with the given URL (useful for API CREATE calls)
34
+ response.should point_to(url)
35
+
36
+ # looks for a 422 response (invalid object)
37
+ response.should be_unprocessable
38
+
39
+ # looks for a 404
40
+ response.should be_not_found
41
+
42
+ # looks for a 401
43
+ response.should be_unauthorised
44
+
45
+ # looks for a 500
46
+ response.should be_an_error
34
47
 
35
48
  == Specifying your controllers
36
49
 
data/Rakefile CHANGED
@@ -1,6 +1,12 @@
1
1
  require 'echoe'
2
2
  Echoe.new('rspec-rails-ext') do | gem |
3
- gem.author = 'Rahoul Baruah'
3
+ gem.author = 'Rahoul Baruah and Caius Durling'
4
+ gem.email = 'support@brightbox.co.uk'
4
5
  gem.summary = 'Helpers for prettying up your RSpec-Rails specifications'
5
- gem.url = 'http://github.com/brightbox-rspec-rails-ext'
6
- end
6
+ gem.url = 'http://github.com/brightbox/rspec-rails-extensions/tree/master'
7
+ end
8
+
9
+ desc "Generates the manifest and the gemspec"
10
+ task :build => [:manifest, :build_gemspec] do
11
+ puts "Built!"
12
+ end
data/lib/mocks.rb ADDED
@@ -0,0 +1,27 @@
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
@@ -1,2 +1,4 @@
1
- require 'matchers'
1
+ require 'spec/rails'
2
+ require 'mocks'
3
+ require 'responses'
2
4
  require 'controller_example_group'
@@ -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.0"
5
+ s.version = "1.0.6"
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-13}
8
+ s.authors = ["Rahoul Baruah and Caius Durling"]
9
+ s.date = %q{2009-02-16}
10
10
  s.description = %q{Helpers for prettying up your RSpec-Rails specifications}
11
- s.email = %q{}
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"]
11
+ s.email = %q{support@brightbox.co.uk}
12
+ s.extra_rdoc_files = ["CHANGELOG", "lib/controller_example_group.rb", "lib/mocks.rb", "lib/responses.rb", "lib/rspec_rails_extensions.rb", "README.rdoc"]
13
+ s.files = ["CHANGELOG", "lib/controller_example_group.rb", "lib/mocks.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-rspec-rails-ext}
15
+ s.homepage = %q{http://github.com/brightbox/rspec-rails-extensions/tree/master}
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,19 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brightbox-rspec-rails-ext
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.0"
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
- - Rahoul Baruah
7
+ - Rahoul Baruah and Caius Durling
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-13 00:00:00 -08:00
12
+ date: 2009-02-16 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
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -22,7 +23,7 @@ dependencies:
22
23
  version: "0"
23
24
  version:
24
25
  description: Helpers for prettying up your RSpec-Rails specifications
25
- email: ""
26
+ email: support@brightbox.co.uk
26
27
  executables: []
27
28
 
28
29
  extensions: []
@@ -30,12 +31,14 @@ extensions: []
30
31
  extra_rdoc_files:
31
32
  - CHANGELOG
32
33
  - lib/controller_example_group.rb
34
+ - lib/mocks.rb
33
35
  - lib/responses.rb
34
36
  - lib/rspec_rails_extensions.rb
35
37
  - README.rdoc
36
38
  files:
37
39
  - CHANGELOG
38
40
  - lib/controller_example_group.rb
41
+ - lib/mocks.rb
39
42
  - lib/responses.rb
40
43
  - lib/rspec_rails_extensions.rb
41
44
  - LICENCE
@@ -44,7 +47,7 @@ files:
44
47
  - README.rdoc
45
48
  - rspec-rails-ext.gemspec
46
49
  has_rdoc: true
47
- homepage: http://github.com/brightbox-rspec-rails-ext
50
+ homepage: http://github.com/brightbox/rspec-rails-extensions/tree/master
48
51
  post_install_message:
49
52
  rdoc_options:
50
53
  - --line-numbers