rspec-set 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 370aeb05e9261700bdfb9557483eca90ff3fa24f
4
+ data.tar.gz: c30b8ef8d0e4850b35c5954c62f6af814d79c2ef
5
+ SHA512:
6
+ metadata.gz: 689c7de2d6373a979c61721e6f48cd89719c7511189fac277eb2a06d2cf75fc03469bb5780a16e8a967addb59f3be11f199164841745538fee2e6ac2bc368a40
7
+ data.tar.gz: 2d8ad60ed0b02ff9e62142245e82418bc093d1efb6493567aaacccf08682db7508ea07eaeb6823b82a8a38a0f5545b21e55fc7fea8019d25c7242dcfa94b1624
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ *.sqlite3
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,25 @@
1
+ # rspec-set CHANGELOG
2
+
3
+ ## 0.1.1
4
+
5
+ * add test suite by [@loganhasson][] (PR [#4][])
6
+ * fix relig destroyed models by [@loganhasson][] (PR [#5][])
7
+
8
+ ## 0.1.0
9
+
10
+ * only reload persisted models
11
+ * relig destroyed models
12
+ * warn when used with non active record objects
13
+ * add support for `rspec >= 2.12` by [@21croissants][]
14
+
15
+ ## 0.0.1
16
+
17
+ * create model in `#before(:all)` statement
18
+ * reload model in `#before(:each)` statement
19
+ * make model available via `#let()`
20
+
21
+ <!--- The following link definition list is generated by PimpMyChangelog --->
22
+ [#4]: https://github.com/pcreux/rspec-set/issues/4
23
+ [#5]: https://github.com/pcreux/rspec-set/issues/5
24
+ [@21croissants]: https://github.com/21croissants
25
+ [@loganhasson]: https://github.com/loganhasson
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in rspec-set.gemspec
4
- gemspec
4
+ gemspec
@@ -1,4 +1,4 @@
1
- = rspec-set
1
+ = rspec-set {<img src="https://travis-ci.org/pcreux/rspec-set.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/pcreux/rspec-set]
2
2
 
3
3
  <tt>#set</tt> is a little RSpec helper that speeds-up drastically integration tests that relies on active record objects.
4
4
 
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -26,8 +26,8 @@ module RSpec
26
26
 
27
27
  if model.is_a?(ActiveRecord::Base)
28
28
  if model.destroyed?
29
- # Relig destroyed model
30
- model.class.find(i.id)
29
+ # Reload destroyed model
30
+ model.class.find(model.id)
31
31
  elsif !model.new_record?
32
32
  # Reload saved model
33
33
  model.reload
@@ -1,5 +1,5 @@
1
1
  module Rspec
2
2
  module Set
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -22,4 +22,8 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec", "~> 2.14.1"
26
+ spec.add_development_dependency "database_cleaner"
27
+ spec.add_development_dependency "activerecord"
28
+ spec.add_development_dependency "sqlite3"
25
29
  end
@@ -0,0 +1,8 @@
1
+ class CreateActiveRecordClassExample < ActiveRecord::Migration
2
+ def change
3
+ create_table :active_record_class_examples do |t|
4
+ t.string :name
5
+ t.integer :age
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,2 @@
1
+ class ActiveRecordClassExample < ActiveRecord::Base
2
+ end
@@ -0,0 +1,11 @@
1
+ class NonActiveRecordClass
2
+ attr_accessor :name
3
+
4
+ def initialize(attributes)
5
+ self.name = attributes[:name]
6
+ end
7
+
8
+ def self.create(attributes)
9
+ new(attributes)
10
+ end
11
+ end
@@ -0,0 +1,165 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'including Set' do
4
+ it 'adds the ::set method to RSpec::Core::ExampleGroup' do
5
+ expect(RSpec::Core::ExampleGroup).to respond_to(:set)
6
+ end
7
+ end
8
+
9
+ describe 'without an ActiveRecord model' do
10
+ setup_for_error_checking(NonActiveRecordClass)
11
+
12
+ it "warns the user that Set only works with AR models" do
13
+ $stderr.rewind
14
+ expect($stderr.string.chomp).to eq(
15
+ "my_object is a NonActiveRecordClass - rspec-set works with ActiveRecord models only"
16
+ )
17
+ end
18
+ end
19
+
20
+ describe 'with an ActiveRecord model' do
21
+ setup_for_error_checking(ActiveRecordClassExample)
22
+
23
+ it "doesn't give a warning to the user" do
24
+ $stderr.rewind
25
+ expect($stderr.string.chomp).to be_empty
26
+ end
27
+
28
+ it 'creates a method based on the argument to ::set' do
29
+ expect(self).to respond_to(:my_object)
30
+ end
31
+ end
32
+
33
+ describe 'with a destroyed ActiveRecord model' do
34
+ set(:my_destroyed_object) do
35
+ ActiveRecordClassExample.create(name: 'Alfred', age: 77)
36
+ end
37
+
38
+ it 'allows us to dstroy a model' do
39
+ my_destroyed_object.destroy
40
+ expect(
41
+ ActiveRecordClassExample.find_by(id: my_destroyed_object.id)
42
+ ).to be_nil
43
+ end
44
+
45
+ it 'reloads a destroyed model' do
46
+ expect(my_destroyed_object.name).to eq('Alfred')
47
+ end
48
+ end
49
+
50
+ describe 'with a stale model' do
51
+ set(:my_stale_object) do
52
+ ActiveRecordClassExample.create(name: 'Old Name', age: 18)
53
+ end
54
+
55
+ it 'allows us to play with the model' do
56
+ my_stale_object.update(name: 'New Name')
57
+ expect(ActiveRecordClassExample.find(my_stale_object.id).name).to eq(
58
+ 'New Name'
59
+ )
60
+ end
61
+
62
+ it 'reloads the stale model' do
63
+ expect(my_stale_object.name).to eq('Old Name')
64
+ end
65
+ end
66
+
67
+
68
+ describe ActiveRecordClassExample do
69
+ set(:ar_class_example) { ActiveRecordClassExample.create(name: 'ex_1') }
70
+
71
+ subject { ar_class_example }
72
+
73
+ context "when name is changed to 'ex_2" do
74
+ before do
75
+ ar_class_example.update(name: 'ex_2')
76
+ end
77
+
78
+ it 'updates the name' do
79
+ expect(subject.name).to eq('ex_2')
80
+ end
81
+ end
82
+
83
+ context "when name is 'ex_1" do
84
+ it 'reloads the original name' do
85
+ expect(subject.name).to eq('ex_1')
86
+ end
87
+ end
88
+ end
89
+
90
+ describe 'sub sub contexts' do
91
+ set(:ar_class_example) { ActiveRecordClassExample.create(name: 'apple') }
92
+
93
+ subject { ar_class_example }
94
+
95
+ context "when name is changed to 'banana'" do
96
+ before do
97
+ ar_class_example.update(name: 'banana')
98
+ end
99
+
100
+ it 'updates the name' do
101
+ expect(subject.name).to eq('banana')
102
+ end
103
+
104
+ context "when we append ' is good'" do
105
+ before do
106
+ ar_class_example.name << ' is good'
107
+ ar_class_example.save
108
+ end
109
+
110
+ it 'updates the appended name' do
111
+ expect(subject.name).to eq('banana is good')
112
+ end
113
+ end
114
+
115
+ context "when we append ' is bad'" do
116
+ before do
117
+ ar_class_example.name << ' is bad'
118
+ ar_class_example.save
119
+ end
120
+
121
+ it 'also updates the appended name' do
122
+ expect(subject.name).to eq('banana is bad')
123
+ end
124
+
125
+ context "when we append ' for you'" do
126
+ before do
127
+ ar_class_example.name << ' for you'
128
+ ar_class_example.save
129
+ end
130
+
131
+ it 'contains the full sentence' do
132
+ expect(subject.name).to eq('banana is bad for you')
133
+ end
134
+ end
135
+ end
136
+ end
137
+
138
+ context "when name is 'apple'" do
139
+ it 'reloads the original name' do
140
+ expect(subject.name).to eq('apple')
141
+ end
142
+ end
143
+ end
144
+
145
+ describe 'deleting an object' do
146
+ set(:ar_class_example) { ActiveRecordClassExample.create(name: 'apple') }
147
+
148
+ subject { ar_class_example }
149
+
150
+ context "when I destroy the ar_class_example" do
151
+ before do
152
+ ar_class_example.destroy
153
+ end
154
+
155
+ it "is destroyed" do
156
+ expect(ActiveRecordClassExample.find_by_id(ar_class_example.id)).to be_nil
157
+ end
158
+ end
159
+
160
+ context "when name is 'apple'" do
161
+ it 'is reloaded from the database' do
162
+ expect(subject.name).to eq('apple')
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,71 @@
1
+ require 'rspec-set'
2
+ require 'database_cleaner'
3
+ require 'active_record'
4
+
5
+ require_relative './fixtures/non_active_record_class'
6
+ require_relative './fixtures/active_record_class_example'
7
+
8
+ RSpec.configure do |config|
9
+ config.treat_symbols_as_metadata_keys_with_true_values = true
10
+ config.run_all_when_everything_filtered = true
11
+ config.filter_run :focus
12
+
13
+ config.before(:suite) do
14
+ setup_database
15
+ end
16
+
17
+ config.after(:suite) do
18
+ destroy_database
19
+ end
20
+
21
+ config.before(:each) do
22
+ DatabaseCleaner.strategy = :transaction
23
+ DatabaseCleaner.start
24
+ end
25
+
26
+ config.after(:each) do
27
+ DatabaseCleaner.clean
28
+ end
29
+
30
+ config.order = 'random'
31
+ end
32
+
33
+ def db
34
+ ActiveRecord::Base.connection
35
+ end
36
+
37
+ def setup_database
38
+ ActiveRecord::Base.establish_connection(
39
+ :adapter => 'sqlite3',
40
+ :database => 'spec/db/rspec-set-test.sqlite3'
41
+ )
42
+
43
+ db.tables.each do |table|
44
+ db.execute("DROP TABLE #{table}")
45
+ end
46
+
47
+ Dir[File.join(File.dirname(__FILE__), "db/migrate", "*.rb")].each do |f|
48
+ require f
49
+ migration = Kernel.const_get(f.split("/").last.split(".rb").first.gsub(/\d+/, "").split("_").collect{|w| w.strip.capitalize}.join())
50
+ migration.migrate(:up)
51
+ end
52
+ end
53
+
54
+ def destroy_database
55
+ db.tables.each do |table|
56
+ db.execute("DROP TABLE #{table}")
57
+ end
58
+ end
59
+
60
+ def setup_for_error_checking(klass)
61
+ before do
62
+ @orig_stderr = $stderr
63
+ $stderr = StringIO.new
64
+ end
65
+
66
+ set(:my_object) { klass.create(name: 'Test Name') }
67
+
68
+ after do
69
+ $stderr = @orig_stderr
70
+ end
71
+ end
metadata CHANGED
@@ -1,46 +1,109 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-set
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Philippe Creux
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-05 00:00:00.000000000 Z
11
+ date: 2014-05-26 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
- requirement: &70356762024000 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.3'
22
20
  type: :development
23
21
  prerelease: false
24
- version_requirements: *70356762024000
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: rake
27
- requirement: &70356762019460 !ruby/object:Gem::Requirement
28
- none: false
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: database_cleaner
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activerecord
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
29
86
  requirements:
30
- - - ! '>='
87
+ - - ">="
31
88
  - !ruby/object:Gem::Version
32
89
  version: '0'
33
90
  type: :development
34
91
  prerelease: false
35
- version_requirements: *70356762019460
36
- description: ! '#set(), speed-up your specs'
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: "#set(), speed-up your specs"
37
98
  email:
38
99
  - pcreux@gmail.com
39
100
  executables: []
40
101
  extensions: []
41
102
  extra_rdoc_files: []
42
103
  files:
43
- - .gitignore
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - CHANGELOG.md
44
107
  - Gemfile
45
108
  - LICENSE.txt
46
109
  - README.rdoc
@@ -49,37 +112,40 @@ files:
49
112
  - lib/rspec-set.rb
50
113
  - lib/version.rb
51
114
  - rspec-set.gemspec
115
+ - spec/db/migrate/01_create_active_record_class_example.rb
116
+ - spec/fixtures/active_record_class_example.rb
117
+ - spec/fixtures/non_active_record_class.rb
118
+ - spec/rspec_set_spec.rb
119
+ - spec/spec_helper.rb
52
120
  homepage: http://github.com/pcreux/rspec-set
53
121
  licenses:
54
122
  - MIT
123
+ metadata: {}
55
124
  post_install_message:
56
125
  rdoc_options: []
57
126
  require_paths:
58
127
  - lib
59
128
  required_ruby_version: !ruby/object:Gem::Requirement
60
- none: false
61
129
  requirements:
62
- - - ! '>='
130
+ - - ">="
63
131
  - !ruby/object:Gem::Version
64
132
  version: '0'
65
- segments:
66
- - 0
67
- hash: -2867062105310348299
68
133
  required_rubygems_version: !ruby/object:Gem::Requirement
69
- none: false
70
134
  requirements:
71
- - - ! '>='
135
+ - - ">="
72
136
  - !ruby/object:Gem::Version
73
137
  version: '0'
74
- segments:
75
- - 0
76
- hash: -2867062105310348299
77
138
  requirements: []
78
139
  rubyforge_project:
79
- rubygems_version: 1.8.11
140
+ rubygems_version: 2.2.0
80
141
  signing_key:
81
- specification_version: 3
82
- summary: ! '#set() is a helper for RSpec which setup active record objects before
83
- all tests and restore them to there original state before each test'
142
+ specification_version: 4
143
+ summary: "#set() is a helper for RSpec which setup active record objects before all
144
+ tests and restore them to there original state before each test"
84
145
  test_files:
85
146
  - features/rspec-set.feature
147
+ - spec/db/migrate/01_create_active_record_class_example.rb
148
+ - spec/fixtures/active_record_class_example.rb
149
+ - spec/fixtures/non_active_record_class.rb
150
+ - spec/rspec_set_spec.rb
151
+ - spec/spec_helper.rb