with_model 1.1.0 → 1.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8cca5256377f4b9344225ea73072ed1da4f9021
4
- data.tar.gz: 88f4236aac8bcfc99d18bc6b2d607b7f6d9e29ba
3
+ metadata.gz: e58c6b921cca191793c25a9d245ed3783b5438dd
4
+ data.tar.gz: 51c4bdcdde34e76a3f807b8feb92f7752479a35d
5
5
  SHA512:
6
- metadata.gz: 9d4dec931009a42eb33bdbfb9c2a0220a427689f0b5fabe1f2ea694d7e82d10974814a6034f870d320db3a56b12db56490b73f4a96834bf418831c18fd55462a
7
- data.tar.gz: 685d7c90874dc1abcc831a4ae76b67d4324792e856854cafa06c6ea9d9af9bf50fc6d76ab05a78196c0e55d009a2a7501456f0284e0218907bb8c7027060bb9f
6
+ metadata.gz: 33c20fcfd6aaa8efc10ffd72b41dba4d115e4ed146dacf42b7b980df368475001a6e72b47a2e99725a46a35836e92571c343d9693527685d5e1b3361ad0933ec
7
+ data.tar.gz: 6914dc77114c8b787b210b6a4618857bac68dc51823d5d80d46b97ab6ee733d338689246551c231d78907105aeb1c9856b8a7abf00ede6619769cb6052391c79
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 1.2.0
2
+
3
+ - Allow specifying scope for before/after blocks (Miks Miķelsons)
4
+
1
5
  ### 1.1.0
2
6
  - Support Ruby 2.1
3
7
  - Support Rails 4.1
@@ -14,16 +18,16 @@
14
18
  ### 0.3.2
15
19
 
16
20
  - Allow calling with_model without a block. (Andrew Marshall)
17
- - Ensure that ActiveSupport's descendants works correctly between tests. (Andrew Marshall)
21
+ - Ensure that ActiveSupports descendants works correctly between tests. (Andrew Marshall)
18
22
  - Allow Active Record 4 in gemspec.
19
23
 
20
24
  ### 0.3.1
21
25
 
22
- - Don't cache connection between tests. (Ryan Ong & Richard Nuno)
26
+ - Dont cache connection between tests. (Ryan Ong & Richard Nuno)
23
27
 
24
28
  ### 0.3
25
29
 
26
- - Use RSpec 2.11's built-in constant stubbing.
30
+ - Use RSpec 2.11s built-in constant stubbing.
27
31
  - Remove RSpec 1.x and Active Record 2.x support.
28
32
  - Remove Mixico support.
29
33
 
data/Gemfile CHANGED
@@ -5,5 +5,5 @@ gemspec
5
5
  gem 'activerecord', :github => 'rails', :branch => ENV['ACTIVE_RECORD_BRANCH'] if ENV['ACTIVE_RECORD_BRANCH']
6
6
  gem 'activerecord', ENV['ACTIVE_RECORD_VERSION'] if ENV['ACTIVE_RECORD_VERSION']
7
7
  gem 'activerecord-jdbcsqlite3-adapter', :platforms => :jruby
8
- gem 'coveralls', :require => false, :platform => :mri_20
9
- gem 'sqlite3', :platforms => :ruby
8
+ gem 'coveralls', :require => false, :platforms => :mri_20
9
+ gem 'sqlite3', '1.3.8', :platforms => :ruby
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2013 Case Commons, LLC
1
+ Copyright (c) 2010-2014 Case Commons, LLC
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # [with_model](https://github.com/Casecommons/with_model)
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/Casecommons/with_model.png?branch=master)](https://travis-ci.org/Casecommons/with_model)
4
- [![Code Climate](https://codeclimate.com/github/Casecommons/with_model.png)](https://codeclimate.com/github/Casecommons/with_model)
5
- [![Coverage Status](https://coveralls.io/repos/Casecommons/with_model/badge.png?branch=master)](https://coveralls.io/r/Casecommons/with_model)
6
- [![Gem Version](https://badge.fury.io/rb/with_model.png)](https://rubygems.org/gems/with_model)
7
- [![Dependency Status](https://gemnasium.com/Casecommons/with_model.png)](https://gemnasium.com/Casecommons/with_model)
3
+ [![Build Status](https://secure.travis-ci.org/Casecommons/with_model.svg?branch=master)](https://travis-ci.org/Casecommons/with_model)
4
+ [![Code Climate](https://img.shields.io/codeclimate/github/Casecommons/with_model.svg)](https://codeclimate.com/github/Casecommons/with_model)
5
+ [![Coverage Status](https://img.shields.io/coveralls/Casecommons/with_model/master.svg)](https://coveralls.io/r/Casecommons/with_model)
6
+ [![Gem Version](https://badge.fury.io/rb/with_model.svg)](https://rubygems.org/gems/with_model)
7
+ [![Dependency Status](https://gemnasium.com/Casecommons/with_model.svg)](https://gemnasium.com/Casecommons/with_model)
8
8
 
9
9
  `with_model` dynamically builds an ActiveRecord model (with table) before each test in a group and destroys it afterwards.
10
10
 
@@ -12,7 +12,7 @@
12
12
 
13
13
  Install as usual: `gem install with_model` or add `gem 'with_model'` to your Gemfile. See `.travis.yml` for supported (tested) Ruby versions.
14
14
 
15
- ## RSpec
15
+ ### RSpec
16
16
 
17
17
  Extend `WithModel` into RSpec:
18
18
 
@@ -24,7 +24,7 @@ RSpec.configure do |config|
24
24
  end
25
25
  ```
26
26
 
27
- ## minitest/spec
27
+ ### minitest/spec
28
28
 
29
29
  Extend `WithModel` into minitest/spec:
30
30
 
@@ -93,7 +93,7 @@ describe "A blog post" do
93
93
  end
94
94
 
95
95
  it "has the module" do
96
- expect(BlogPost.include?(SomeModule)).to be_true
96
+ expect(BlogPost.include?(SomeModule)).to eq true
97
97
  end
98
98
 
99
99
  it "has the class method" do
@@ -109,7 +109,7 @@ describe "A blog post" do
109
109
  expect(record).to_not be_valid
110
110
  record.title = "foo"
111
111
  expect(record).to be_valid
112
- expect(record.save).to be_true
112
+ expect(record.save).to eq true
113
113
  expect(record.reload).to eq record
114
114
  record.comments.create!(:text => "Lorem ipsum")
115
115
  expect(record.comments.count).to eq 1
@@ -124,13 +124,29 @@ describe "A blog post" do
124
124
  end
125
125
 
126
126
  it "has a specified superclass" do
127
- expect(Ford < Car).to be_true
127
+ expect(Ford < Car).to eq true
128
+ end
129
+ end
130
+
131
+ describe "with_model can be run within RSpec :all hook" do
132
+ with_model :BlogPost, scope: :all do
133
+ table do |t|
134
+ t.string :title
135
+ end
136
+ end
137
+
138
+ before :all do
139
+ BlogPost.create # without scope: :all these will fail
140
+ end
141
+
142
+ it "has been initialized within before(:all)" do
143
+ expect(BlogPost.count).to eq 1
128
144
  end
129
145
  end
130
146
 
131
147
  describe "another example group" do
132
148
  it "does not have the constant anymore" do
133
- expect(defined?(BlogPost)).to be_false
149
+ expect(defined?(BlogPost)).to be_falsy
134
150
  end
135
151
  end
136
152
 
@@ -40,7 +40,7 @@ module WithModel
40
40
  private
41
41
 
42
42
  def const_name
43
- @name.to_s.camelize.freeze
43
+ @name.to_s.camelize.to_sym
44
44
  end
45
45
 
46
46
  def setup_model
@@ -1,3 +1,3 @@
1
1
  module WithModel
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
data/lib/with_model.rb CHANGED
@@ -5,18 +5,34 @@ require 'with_model/version'
5
5
 
6
6
  module WithModel
7
7
  def with_model(name, options = {}, &block)
8
+ options = options.dup
9
+ scope = options.delete(:scope)
10
+
8
11
  model = Model.new name, options
9
12
  dsl = Model::DSL.new model
10
13
  dsl.instance_exec(&block) if block
11
14
 
12
- before { model.create }
13
- after { model.destroy }
15
+ before(*scope) do
16
+ model.create
17
+ end
18
+
19
+ after(*scope) do
20
+ model.destroy
21
+ end
14
22
  end
15
23
 
16
24
  def with_table(name, options = {}, &block)
25
+ options = options.dup
26
+ scope = options.delete(:scope)
27
+
17
28
  table = Table.new name, options, &block
18
29
 
19
- before { table.create }
20
- after { table.destroy }
30
+ before(*scope) do
31
+ table.create
32
+ end
33
+
34
+ after(*scope) do
35
+ table.destroy
36
+ end
21
37
  end
22
38
  end
data/spec/readme_spec.rb CHANGED
@@ -50,7 +50,7 @@ describe "A blog post" do
50
50
  end
51
51
 
52
52
  it "has the module" do
53
- expect(BlogPost.include?(SomeModule)).to be_true
53
+ expect(BlogPost.include?(SomeModule)).to eq true
54
54
  end
55
55
 
56
56
  it "has the class method" do
@@ -66,7 +66,7 @@ describe "A blog post" do
66
66
  expect(record).to_not be_valid
67
67
  record.title = "foo"
68
68
  expect(record).to be_valid
69
- expect(record.save).to be_true
69
+ expect(record.save).to eq true
70
70
  expect(record.reload).to eq record
71
71
  record.comments.create!(:text => "Lorem ipsum")
72
72
  expect(record.comments.count).to eq 1
@@ -81,13 +81,29 @@ describe "A blog post" do
81
81
  end
82
82
 
83
83
  it "has a specified superclass" do
84
- expect(Ford < Car).to be_true
84
+ expect(Ford < Car).to eq true
85
+ end
86
+ end
87
+
88
+ describe "with_model can be run within RSpec :all hook" do
89
+ with_model :BlogPost, scope: :all do
90
+ table do |t|
91
+ t.string :title
92
+ end
93
+ end
94
+
95
+ before :all do
96
+ BlogPost.create # without scope: :all these will fail
97
+ end
98
+
99
+ it "has been initialized within before(:all)" do
100
+ expect(BlogPost.count).to eq 1
85
101
  end
86
102
  end
87
103
 
88
104
  describe "another example group" do
89
105
  it "does not have the constant anymore" do
90
- expect(defined?(BlogPost)).to be_false
106
+ expect(defined?(BlogPost)).to be_falsy
91
107
  end
92
108
  end
93
109
 
data/spec/spec_helper.rb CHANGED
@@ -44,7 +44,7 @@ module SpecHelper
44
44
  if ::ActiveRecord::VERSION::STRING >= '4.1.0'
45
45
  require 'minitest'
46
46
  include Minitest::Assertions
47
- def assertions; @assertions || 0; end
47
+ def assertions; @assertions ||= 0; end
48
48
  def assertions= value; @assertions = value; end
49
49
  else
50
50
  require 'test/unit/assertions'
@@ -70,7 +70,7 @@ describe "a temporary ActiveRecord model created with with_model" do
70
70
 
71
71
  describe ".with_model?" do
72
72
  it "returns true" do
73
- expect(BlogPost.with_model?).to be_true
73
+ expect(BlogPost.with_model?).to eq true
74
74
  end
75
75
  end
76
76
 
@@ -81,8 +81,8 @@ describe "a temporary ActiveRecord model created with with_model" do
81
81
 
82
82
  context "after an example which uses with_model without shadowing an existing constant" do
83
83
  it "returns the constant to its undefined state" do
84
- expect(non_shadowing_example_ran).to be_true
85
- expect(defined?(BlogPost)).to be_false
84
+ expect(non_shadowing_example_ran).to eq true
85
+ expect(defined?(BlogPost)).to be_falsy
86
86
  end
87
87
  end
88
88
 
@@ -104,7 +104,7 @@ describe "a temporary ActiveRecord model created with with_model" do
104
104
 
105
105
  context "in later examples" do
106
106
  it "returns the constant to its original value" do
107
- expect(shadowing_example_ran).to be_true
107
+ expect(shadowing_example_ran).to eq true
108
108
  expect(MyConst).to eq 1
109
109
  end
110
110
  end
@@ -166,7 +166,7 @@ describe "a temporary ActiveRecord model created with with_model" do
166
166
 
167
167
  it "has the mixin" do
168
168
  expect(lambda { ::ModelWithMixin.new.foo }).to_not raise_error
169
- expect(::ModelWithMixin.include?(AMixin)).to be_true
169
+ expect(::ModelWithMixin.include?(AMixin)).to eq true
170
170
  end
171
171
  end
172
172
 
@@ -308,6 +308,22 @@ describe "a temporary ActiveRecord model created with with_model" do
308
308
  end
309
309
  end
310
310
 
311
+ context "with_model can be run within RSpec :all hook" do
312
+ with_model :BlogPost, scope: :all do
313
+ table do |t|
314
+ t.string :title
315
+ end
316
+ end
317
+
318
+ before :all do
319
+ BlogPost.create # without scope: :all these will fail
320
+ end
321
+
322
+ it "has been initialized within before(:all)" do
323
+ expect(BlogPost.count).to eq 1
324
+ end
325
+ end
326
+
311
327
  context "with 'superclass' option" do
312
328
  class BlogPostParent < ActiveRecord::Base
313
329
  self.abstract_class = true
@@ -325,7 +341,7 @@ describe "a temporary ActiveRecord model created with with_model" do
325
341
  end
326
342
 
327
343
  it "is a subclass of the supplied superclass" do
328
- expect(BlogPost < BlogPostParent).to be_true
344
+ expect(BlogPost < BlogPostParent).to eq true
329
345
  end
330
346
 
331
347
  it "is its own base_class" do
@@ -333,7 +349,7 @@ describe "a temporary ActiveRecord model created with with_model" do
333
349
  end
334
350
 
335
351
  it "responds to .with_model? with true" do
336
- expect(BlogPost.with_model?).to be_true
352
+ expect(BlogPost.with_model?).to eq true
337
353
  end
338
354
  end
339
355
  end
data/with_model.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_development_dependency 'bundler', '~> 1.3'
25
25
  spec.add_development_dependency 'rake'
26
- spec.add_development_dependency 'rspec', '~> 2.14'
26
+ spec.add_development_dependency 'rspec', '>= 2.14', '< 4'
27
27
  spec.add_development_dependency 'rubysl' if RUBY_ENGINE == 'rbx'
28
28
  spec.add_development_dependency 'rubysl-test-unit' if RUBY_ENGINE == 'rbx'
29
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: with_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Case Commons, LLC
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-15 00:00:00.000000000 Z
12
+ date: 2014-06-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -63,16 +63,22 @@ dependencies:
63
63
  name: rspec
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.14'
69
+ - - "<"
70
+ - !ruby/object:Gem::Version
71
+ version: '4'
69
72
  type: :development
70
73
  prerelease: false
71
74
  version_requirements: !ruby/object:Gem::Requirement
72
75
  requirements:
73
- - - "~>"
76
+ - - ">="
74
77
  - !ruby/object:Gem::Version
75
78
  version: '2.14'
79
+ - - "<"
80
+ - !ruby/object:Gem::Version
81
+ version: '4'
76
82
  description: Dynamically build a model within an RSpec context
77
83
  email:
78
84
  - casecommons-dev@googlegroups.com
@@ -122,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
128
  version: '0'
123
129
  requirements: []
124
130
  rubyforge_project:
125
- rubygems_version: 2.2.2
131
+ rubygems_version: 2.3.0
126
132
  signing_key:
127
133
  specification_version: 4
128
134
  summary: Dynamically build a model within an RSpec context
@@ -131,3 +137,4 @@ test_files:
131
137
  - spec/readme_spec.rb
132
138
  - spec/spec_helper.rb
133
139
  - spec/with_model_spec.rb
140
+ has_rdoc: