blunt_stub_factory 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b28dedc5ea8959a845e8b1aadc8476d40c386ed0
4
- data.tar.gz: e0e64b1248c8e3e98a0e8fc96857eb9bf1938ff7
3
+ metadata.gz: 5891a3f4ef0b257a71df4f74e66bb3c67cfe3b1e
4
+ data.tar.gz: 7fb27f94176c2d1bcf7e94e955e529d29315d344
5
5
  SHA512:
6
- metadata.gz: e056ee77751634e4958a5c29be3cdb23afc5f6bf08e7a06ccbac632ee9ce4cfa1062e725276b758e2266d3624f4db980a423d5f59ca66d19c106620d2aa246e8
7
- data.tar.gz: b4b26b7f052e4b9e91cc97553792b8d16462b7979be4b5c2055d05f092703dfb10fb0713abd3ab93311122db0a49079732f33e5cfb2f24a5b3c87f7ab09cabee
6
+ metadata.gz: 37cd615fd2dd6a1809dca2db6156adfef0fea934950eab64350d07bf9c7b7294cfb66fe6ba43215e2af968a432150dcd52e6884842169a526b53093998ed488d
7
+ data.tar.gz: 3061def43f2c37316808043e65e9671445a0c673fb3587aae63d67af1fb8bc54792cc9d82a25de944cb2e4ed8e3afb07024343b48ea3fbb95145e112953799a1
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.0.0"
4
+ #- jruby-20mode
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in stub_factory.gemspec
4
4
  gemspec
5
+ gem 'coveralls', require: false
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
1
  # StubFactory
2
+ [![Build Status](https://travis-ci.org/LFDM/stub_factory.png)](https://travis-ci.org/LFDM/stub_factory)
3
+ [![Coverage Status](https://coveralls.io/repos/LFDM/stub_factory/badge.png)](https://coveralls.io/r/LFDM/stub_factory)
4
+ [![Dependency Status](https://gemnasium.com/LFDM/stub_factory.png)](https://gemnasium.com/LFDM/stub_factory)
2
5
 
3
6
  A blunt StubFactory that helps to test tightly coupled code, but handle with care: This is not a best practice. If you find yourself relying on this a lot, you might have to rethink your design.
4
7
 
@@ -6,7 +9,7 @@ A blunt StubFactory that helps to test tightly coupled code, but handle with car
6
9
 
7
10
  Add this line to your application's Gemfile:
8
11
 
9
- gem 'stub_factory'
12
+ gem 'blunt_stub_factory', require: 'stub_factory'
10
13
 
11
14
  And then execute:
12
15
 
@@ -14,12 +17,13 @@ And then execute:
14
17
 
15
18
  Or install it yourself as:
16
19
 
17
- $ gem install stub_factory
20
+ $ gem install blunt_stub_factory
18
21
 
19
22
  ## Usage
20
23
 
21
24
  ```ruby
22
25
  require 'stub_factory'
26
+ # beware: StubFactory resides in the stub_factory file, not as it's gemname would indicate (the name stub_factory was already taken...)
23
27
 
24
28
  Class A
25
29
  attr_reader :test, :test2
@@ -48,7 +52,7 @@ b.test
48
52
  ```
49
53
 
50
54
  Default as well as custom templates to overwrite variables can be defined - StubFactory automatically looks for such statements
51
- in your spec/factories folder.
55
+ in your spec/factories folder. Only files named template_***.rb are loaded.
52
56
  ```ruby
53
57
  StubFactory.define_template(:a) do
54
58
  { test2 = "template value" }
@@ -86,7 +90,7 @@ b.a_method
86
90
  ```
87
91
 
88
92
  For ease of use, helper methods can be defined when they are included in your RSpec configuarion.
89
- Place define_helper statements in your spec/support/helpers folder.
93
+ Place define_helper statements in your spec/support/helpers folder. Only files named stub_***.rb are loaded.
90
94
  ```ruby
91
95
  RSpec.configure do |config|
92
96
  config.include StubFactory::Helpers
data/Rakefile CHANGED
@@ -1,8 +1,11 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require 'coveralls/rake/task'
4
+
5
+ Coveralls::RakeTask.new
3
6
 
4
7
  RSpec::Core::RakeTask.new(:spec) do |t|
5
8
  t.rspec_opts = '-f d --color'
6
9
  end
7
10
 
8
- task :default => :spec
11
+ task :default => [:spec, 'coveralls:push']
data/lib/stub_factory.rb CHANGED
@@ -59,7 +59,7 @@ module StubFactory
59
59
  path = File.expand_path(rel_path)
60
60
 
61
61
  if File.exists?(path)
62
- require "#{path}" if File.file?(path)
62
+ require "#{path}" if File.file?(path) && path.match(/\/(stub_|template_)[^\/]*$/)
63
63
  Dir["#{path}/*"].each { |file| require_path(file) }
64
64
  end
65
65
  end
@@ -1,3 +1,3 @@
1
1
  module StubFactory
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,3 @@
1
+ StubFactory.define_template(:wrong_template) do
2
+ { test: 11 }
3
+ end
@@ -1,10 +1,6 @@
1
+ require 'spec_helper'
1
2
  require 'stub_factory'
2
3
 
3
- # Methods defined by .define_helper will not work without this:
4
- RSpec.configure do |config|
5
- config.include StubFactory::Helpers
6
- end
7
-
8
4
  describe StubFactory do
9
5
  before :all do
10
6
  # the attr reader is set for convenience
@@ -46,10 +42,15 @@ describe StubFactory do
46
42
  expect { StubFactory.define_helper(:helper2, :A) }.to raise_error(StubFactory::HelperError)
47
43
  end
48
44
 
49
- it "helpers can be defined in files - default path is spec/support/helpers" do
50
- # required_helper is defined in #spec/support/helper_test.rb
45
+ it "helpers can be defined in files called stub_***.rb - default path is spec/support/helpers" do
46
+ # required_helper is defined in #spec/support/stub_helper_test.rb
51
47
  stub_required_helper.should be_an_instance_of A
52
48
  end
49
+
50
+ it "to allow other files in this folder wrongly named files are not consumed" do
51
+ # wrong_helper is defined in #spec/support/wrong_helper_test.rb
52
+ expect { stub_wrong_helper }.to raise_error NameError
53
+ end
53
54
  end
54
55
 
55
56
  describe "#new_stub" do
@@ -82,10 +83,16 @@ describe StubFactory do
82
83
  o.test.should be_nil
83
84
  end
84
85
 
85
- it "templates can be defined in files - their default path is spec/factories" do
86
+ it "templates can be defined in files called template_**.rb - their default path is spec/factories" do
86
87
  # required_template is defined in #spec/factories/template_test.rb
87
88
  A.new_stub(template: :required_template).test.should == 11
88
89
  end
90
+
91
+ it "to allow other files in this folder wrongly named files are not consumed" do
92
+ # wrong_template is defined in #spec/factories/wrong_test.rb
93
+ # with the variable test == 11
94
+ A.new_stub(template: :wrong_template).test.should be_nil
95
+ end
89
96
  end
90
97
 
91
98
  context "when a custom template exists" do
@@ -0,0 +1,20 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ Coveralls.wear!
5
+
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
10
+
11
+ SimpleCov.start do
12
+ add_filter '/spec/'
13
+ end
14
+
15
+ require 'stub_factory'
16
+
17
+ # Methods defined by .define_helper will not work without this:
18
+ RSpec.configure do |config|
19
+ config.include StubFactory::Helpers
20
+ end
@@ -0,0 +1 @@
1
+ StubFactory.define_helper(:wrong_helper, :A)
data/stub_factory.gemspec CHANGED
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "simplecov", "~> 0.7"
24
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blunt_stub_factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - LFDM
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-12 00:00:00.000000000 Z
11
+ date: 2013-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.7'
55
69
  description: Simple StubFactory for rspec
56
70
  email:
57
71
  - 1986gh@gmail.com
@@ -60,6 +74,7 @@ extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
62
76
  - .gitignore
77
+ - .travis.yml
63
78
  - Gemfile
64
79
  - LICENSE.txt
65
80
  - README.md
@@ -69,8 +84,11 @@ files:
69
84
  - lib/stub_factory/helpers.rb
70
85
  - lib/stub_factory/version.rb
71
86
  - spec/factories/template_test.rb
87
+ - spec/factories/wrong_test.rb
72
88
  - spec/lib/stub_factory_spec.rb
73
- - spec/support/helpers/helper_test.rb
89
+ - spec/spec_helper.rb
90
+ - spec/support/helpers/stub_helper_test.rb
91
+ - spec/support/helpers/wrong_helper_test.rb
74
92
  - stub_factory.gemspec
75
93
  homepage: ''
76
94
  licenses:
@@ -98,6 +116,8 @@ specification_version: 4
98
116
  summary: Simple StubFactory for rspec, that can help with tightly coupled code
99
117
  test_files:
100
118
  - spec/factories/template_test.rb
119
+ - spec/factories/wrong_test.rb
101
120
  - spec/lib/stub_factory_spec.rb
102
- - spec/support/helpers/helper_test.rb
103
- has_rdoc:
121
+ - spec/spec_helper.rb
122
+ - spec/support/helpers/stub_helper_test.rb
123
+ - spec/support/helpers/wrong_helper_test.rb