f-matchers 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,22 @@
|
|
1
1
|
# return true is the model accept nested attributes for the passed attribute
|
2
2
|
RSpec::Matchers.define :accept_nested_attributes_for do |attribute|
|
3
3
|
match do |model|
|
4
|
-
model.
|
4
|
+
klazz = model.respond_to?(:new) ? model : model.class
|
5
|
+
klazz.nested_attributes_options.include? attribute
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
# spec for attr_protected declarations
|
10
|
+
RSpec::Matchers.define :protect_attribute do |attribute|
|
11
|
+
match do |model|
|
12
|
+
klazz = model.respond_to?(:new) ? model : model.class
|
13
|
+
protected = klazz.protected_attributes
|
14
|
+
protected.include? attribute if protected
|
15
|
+
end
|
16
|
+
failure_message_for_should do
|
17
|
+
"#{subject.class} should protect attribute #{attribute.inspect}"
|
18
|
+
end
|
19
|
+
failure_message_for_should_not do
|
20
|
+
"#{subject.class} should not protect attribute #{attribute.inspect}"
|
5
21
|
end
|
6
22
|
end
|
data/lib/f-matchers/version.rb
CHANGED
data/spec/rspec_matchers_spec.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
require "support/rspec_f_matchers"
|
3
2
|
|
4
3
|
describe "rspec_f_matchers" do
|
4
|
+
|
5
|
+
subject{Document}
|
5
6
|
|
6
|
-
context "accept_nested_attributes_for" do
|
7
|
-
|
8
|
-
it
|
9
|
-
|
10
|
-
end
|
7
|
+
context "accept_nested_attributes_for" do
|
8
|
+
it { should accept_nested_attributes_for(:section) }
|
9
|
+
it { should_not accept_nested_attributes_for(:users) }
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
context "protect_attribute" do
|
13
|
+
it { should protect_attribute(:protect_me) }
|
14
|
+
it { should_not protect_attribute(:do_not_protect_me) }
|
16
15
|
end
|
17
16
|
|
18
17
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,12 @@
|
|
1
1
|
require "f-matchers"
|
2
|
+
require "active_record"
|
3
|
+
|
4
|
+
FileUtils.mkdir_p File.dirname(__FILE__) + '/../db/'
|
5
|
+
ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => "db/test.sqlite3"
|
6
|
+
ActiveRecord::Base.connection.create_table(:documents,:force => true) do |t|
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
|
2
10
|
|
3
11
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
12
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
@@ -10,4 +18,13 @@ RSpec.configure do |config|
|
|
10
18
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
19
|
config.run_all_when_everything_filtered = true
|
12
20
|
config.filter_run :focus
|
21
|
+
|
22
|
+
config.before(:each) do
|
23
|
+
Document.delete_all
|
24
|
+
end
|
25
|
+
|
26
|
+
config.after(:suite) do
|
27
|
+
ActiveRecord::Base.connection.drop_table(:documents)
|
28
|
+
end
|
29
|
+
|
13
30
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: f-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-20 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70211466243980 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70211466243980
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activerecord
|
27
|
-
requirement: &
|
27
|
+
requirement: &70211466243560 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70211466243560
|
36
36
|
description: Rspec matchers
|
37
37
|
email:
|
38
38
|
- acampolonghi@gmail.com
|
@@ -51,7 +51,7 @@ files:
|
|
51
51
|
- lib/f-matchers/version.rb
|
52
52
|
- spec/rspec_matchers_spec.rb
|
53
53
|
- spec/spec_helper.rb
|
54
|
-
- spec/support/
|
54
|
+
- spec/support/models.rb
|
55
55
|
homepage: ''
|
56
56
|
licenses: []
|
57
57
|
post_install_message:
|
@@ -79,5 +79,5 @@ summary: Rspec matchers
|
|
79
79
|
test_files:
|
80
80
|
- spec/rspec_matchers_spec.rb
|
81
81
|
- spec/spec_helper.rb
|
82
|
-
- spec/support/
|
82
|
+
- spec/support/models.rb
|
83
83
|
has_rdoc:
|