auto_mock 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ source "http://rubygems.org"
3
+
4
+ gem "rspec"
5
+ gem "rails"
6
+
7
+ group :development do
8
+ gem "bundler", "~> 1.0.0"
9
+ gem "jeweler", "~> 1.5.1"
10
+ gem "rcov", ">= 0"
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,90 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.3)
6
+ actionpack (= 3.0.3)
7
+ mail (~> 2.2.9)
8
+ actionpack (3.0.3)
9
+ activemodel (= 3.0.3)
10
+ activesupport (= 3.0.3)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.4)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.13)
16
+ rack-test (~> 0.5.6)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.3)
19
+ activesupport (= 3.0.3)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.4)
22
+ activerecord (3.0.3)
23
+ activemodel (= 3.0.3)
24
+ activesupport (= 3.0.3)
25
+ arel (~> 2.0.2)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.3)
28
+ activemodel (= 3.0.3)
29
+ activesupport (= 3.0.3)
30
+ activesupport (3.0.3)
31
+ arel (2.0.6)
32
+ builder (2.1.2)
33
+ diff-lcs (1.1.2)
34
+ erubis (2.6.6)
35
+ abstract (>= 1.0.0)
36
+ git (1.2.5)
37
+ i18n (0.5.0)
38
+ jeweler (1.5.1)
39
+ bundler (~> 1.0.0)
40
+ git (>= 1.2.5)
41
+ rake
42
+ mail (2.2.12)
43
+ activesupport (>= 2.3.6)
44
+ i18n (>= 0.4.0)
45
+ mime-types (~> 1.16)
46
+ treetop (~> 1.4.8)
47
+ mime-types (1.16)
48
+ polyglot (0.3.1)
49
+ rack (1.2.1)
50
+ rack-mount (0.6.13)
51
+ rack (>= 1.0.0)
52
+ rack-test (0.5.6)
53
+ rack (>= 1.0)
54
+ rails (3.0.3)
55
+ actionmailer (= 3.0.3)
56
+ actionpack (= 3.0.3)
57
+ activerecord (= 3.0.3)
58
+ activeresource (= 3.0.3)
59
+ activesupport (= 3.0.3)
60
+ bundler (~> 1.0)
61
+ railties (= 3.0.3)
62
+ railties (3.0.3)
63
+ actionpack (= 3.0.3)
64
+ activesupport (= 3.0.3)
65
+ rake (>= 0.8.7)
66
+ thor (~> 0.14.4)
67
+ rake (0.8.7)
68
+ rcov (0.9.9)
69
+ rspec (2.2.0)
70
+ rspec-core (~> 2.2)
71
+ rspec-expectations (~> 2.2)
72
+ rspec-mocks (~> 2.2)
73
+ rspec-core (2.2.1)
74
+ rspec-expectations (2.2.0)
75
+ diff-lcs (~> 1.1.2)
76
+ rspec-mocks (2.2.0)
77
+ thor (0.14.6)
78
+ treetop (1.4.9)
79
+ polyglot (>= 0.3.1)
80
+ tzinfo (0.3.23)
81
+
82
+ PLATFORMS
83
+ ruby
84
+
85
+ DEPENDENCIES
86
+ bundler (~> 1.0.0)
87
+ jeweler (~> 1.5.1)
88
+ rails
89
+ rcov
90
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 masarakki
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,28 @@
1
+ = auto_mock
2
+ you dont have to write 'def mock_xxx(stubs={})...' any longer.
3
+
4
+ == Install
5
+ First, you must setup rspec by
6
+ rails generate rspec:install
7
+
8
+ Then,
9
+ rails generate auto_mock
10
+
11
+ == Deinstall
12
+ delete 'include AutoMock::AutoMockHelper' line in your spec/spec_helper.rb
13
+
14
+ == Contributing to auto_mock
15
+
16
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
17
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
18
+ * Fork the project
19
+ * Start a feature/bugfix branch
20
+ * Commit and push until you are happy with your contribution
21
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
22
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
23
+
24
+ == Copyright
25
+
26
+ Copyright (c) 2010 masarakki. See LICENSE.txt for
27
+ further details.
28
+
data/Rakefile ADDED
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "auto_mock"
16
+ gem.homepage = "http://github.com/masarakki/auto_mock"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{auto define mock_xxxx methods}
19
+ gem.description = %Q{auto define mock_xxx methods}
20
+ gem.email = "masaki@hisme.net"
21
+ gem.authors = ["masarakki"]
22
+ gem.post_install_message = %Q{*****************************
23
+ To enable to use auto_mock,
24
+
25
+ rails generate auto_mock
26
+
27
+ *****************************
28
+ }
29
+
30
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
31
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
32
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
33
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
34
+ end
35
+ Jeweler::RubygemsDotOrgTasks.new
36
+
37
+ require 'rspec/core'
38
+ require 'rspec/core/rake_task'
39
+ RSpec::Core::RakeTask.new(:spec) do |spec|
40
+ spec.pattern = FileList['spec/**/*_spec.rb']
41
+ end
42
+
43
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
44
+ spec.pattern = 'spec/**/*_spec.rb'
45
+ spec.rcov = true
46
+ end
47
+
48
+ task :default => :spec
49
+
50
+ require 'rake/rdoctask'
51
+ Rake::RDocTask.new do |rdoc|
52
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
53
+
54
+ rdoc.rdoc_dir = 'rdoc'
55
+ rdoc.title = "auto_mock #{version}"
56
+ rdoc.rdoc_files.include('README*')
57
+ rdoc.rdoc_files.include('lib/**/*.rb')
58
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/auto_mock.gemspec ADDED
@@ -0,0 +1,77 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{auto_mock}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["masarakki"]
12
+ s.date = %q{2010-12-09}
13
+ s.description = %q{auto define mock_xxx methods}
14
+ s.email = %q{masaki@hisme.net}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "auto_mock.gemspec",
29
+ "lib/auto_mock.rb",
30
+ "lib/auto_mock/auto_mock_helper.rb",
31
+ "lib/generators/auto_mock/auto_mock_generator.rb",
32
+ "spec/auto_mock_spec.rb",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/masarakki/auto_mock}
36
+ s.licenses = ["MIT"]
37
+ s.post_install_message = %q{*****************************
38
+ To enable to use auto_mock,
39
+
40
+ rails generate auto_mock
41
+
42
+ *****************************
43
+ }
44
+ s.require_paths = ["lib"]
45
+ s.rubygems_version = %q{1.3.7}
46
+ s.summary = %q{auto define mock_xxxx methods}
47
+ s.test_files = [
48
+ "spec/auto_mock_spec.rb",
49
+ "spec/spec_helper.rb"
50
+ ]
51
+
52
+ if s.respond_to? :specification_version then
53
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
+ s.specification_version = 3
55
+
56
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
+ s.add_runtime_dependency(%q<rspec>, [">= 0"])
58
+ s.add_runtime_dependency(%q<rails>, [">= 0"])
59
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
60
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
61
+ s.add_development_dependency(%q<rcov>, [">= 0"])
62
+ else
63
+ s.add_dependency(%q<rspec>, [">= 0"])
64
+ s.add_dependency(%q<rails>, [">= 0"])
65
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
66
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
67
+ s.add_dependency(%q<rcov>, [">= 0"])
68
+ end
69
+ else
70
+ s.add_dependency(%q<rspec>, [">= 0"])
71
+ s.add_dependency(%q<rails>, [">= 0"])
72
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
73
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
74
+ s.add_dependency(%q<rcov>, [">= 0"])
75
+ end
76
+ end
77
+
@@ -0,0 +1,31 @@
1
+ module AutoMock
2
+ module AutoMockHelper
3
+ def method_missing(name, *args)
4
+ if matched = name.to_s.match(/mock_(.*)/)
5
+ klass = matched[1].classify.constantize
6
+ multi_name = "mock_#{klass.name.tableize}".to_sym
7
+
8
+ array_name = "@#{multi_name.to_s}"
9
+ self.class.send(:define_method, multi_name) do |key, *stubs|
10
+ stubs = stubs.try(:first) || {}
11
+ array = instance_variable_get(array_name) || {}
12
+ if array.has_key?(key)
13
+ return array[key]
14
+ end
15
+ array[key] = mock_model(klass, stubs)
16
+ instance_variable_set(array_name, array)
17
+ array[key]
18
+ end
19
+
20
+ single_name = "mock_#{klass.name.tableize.singularize}".to_sym
21
+ self.class.send(:define_method, single_name) do |*stubs|
22
+ send(:single_name, :default, stubs)
23
+ end
24
+
25
+ send(name, *args)
26
+ else
27
+ super
28
+ end
29
+ end
30
+ end
31
+ end
data/lib/auto_mock.rb ADDED
@@ -0,0 +1,3 @@
1
+ module AutoMock
2
+ autoload :AutoMockHelper, 'auto_mock/auto_mock_helper'
3
+ end
@@ -0,0 +1,31 @@
1
+ require 'rails/generators/base'
2
+
3
+ module AutoMock
4
+ module Generators
5
+ class AutoMockGenerator < Rails::Generators::Base
6
+
7
+ desc <<DESC
8
+ Description:
9
+ Add include syntax to use auto_mock in your spec_helper
10
+ DESC
11
+ def self.source_root
12
+ @_auto_mock_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
13
+ end
14
+
15
+ def insert_include
16
+ spec_helper = 'spec/spec_helper.rb'
17
+ if File.exists?(spec_helper) && File.readlines(spec_helper).grep(/include AutoMock::AutoMockHelper/).blank?
18
+ File.open(spec_helper, 'a') do |f|
19
+ f.puts 'include AutoMock::AutoMockHelper'
20
+ end
21
+ else
22
+ raise Rails::Generators::Error, "First, you must setup rspec by 'rails generate rspec:install'"
23
+ end
24
+ end
25
+
26
+ def app_name
27
+ Rails.application.class.name
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "AutoMock" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'auto_mock'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auto_mock
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - masarakki
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-09 00:00:00 +09:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ prerelease: false
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: rails
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
42
+ version: "0"
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: &id003 !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 1
55
+ - 0
56
+ - 0
57
+ version: 1.0.0
58
+ type: :development
59
+ prerelease: false
60
+ version_requirements: *id003
61
+ - !ruby/object:Gem::Dependency
62
+ name: jeweler
63
+ requirement: &id004 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 1
70
+ - 5
71
+ - 1
72
+ version: 1.5.1
73
+ type: :development
74
+ prerelease: false
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: rcov
78
+ requirement: &id005 !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: *id005
89
+ description: auto define mock_xxx methods
90
+ email: masaki@hisme.net
91
+ executables: []
92
+
93
+ extensions: []
94
+
95
+ extra_rdoc_files:
96
+ - LICENSE.txt
97
+ - README.rdoc
98
+ files:
99
+ - .document
100
+ - .rspec
101
+ - Gemfile
102
+ - Gemfile.lock
103
+ - LICENSE.txt
104
+ - README.rdoc
105
+ - Rakefile
106
+ - VERSION
107
+ - auto_mock.gemspec
108
+ - lib/auto_mock.rb
109
+ - lib/auto_mock/auto_mock_helper.rb
110
+ - lib/generators/auto_mock/auto_mock_generator.rb
111
+ - spec/auto_mock_spec.rb
112
+ - spec/spec_helper.rb
113
+ has_rdoc: true
114
+ homepage: http://github.com/masarakki/auto_mock
115
+ licenses:
116
+ - MIT
117
+ post_install_message: |
118
+ *****************************
119
+ To enable to use auto_mock,
120
+
121
+ rails generate auto_mock
122
+
123
+ *****************************
124
+
125
+ rdoc_options: []
126
+
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ hash: -604345055
135
+ segments:
136
+ - 0
137
+ version: "0"
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ segments:
144
+ - 0
145
+ version: "0"
146
+ requirements: []
147
+
148
+ rubyforge_project:
149
+ rubygems_version: 1.3.7
150
+ signing_key:
151
+ specification_version: 3
152
+ summary: auto define mock_xxxx methods
153
+ test_files:
154
+ - spec/auto_mock_spec.rb
155
+ - spec/spec_helper.rb