genspec 0.2.0.prerails3.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/genspec.rb CHANGED
@@ -1,6 +1,7 @@
1
- if defined?(RAILS_ROOT)
1
+ require 'thor'
2
+ if defined?(Rails)
2
3
  if Rails::VERSION::MAJOR == 2
3
- raise "Use genspec 0.1.0 for Rails 2; this version is for Rails 3."
4
+ raise "Use genspec 0.1.x for Rails 2; this version is for Rails 3."
4
5
  elsif Rails::VERSION::MAJOR == 3
5
6
  require 'rails/generators'
6
7
  else
@@ -17,13 +18,23 @@ end
17
18
  require 'fileutils'
18
19
 
19
20
  require 'sc-core-ext'
21
+ require 'genspec/version' unless defined?(GenSpec::VERSION)
20
22
  require 'genspec/shell'
21
23
  require 'genspec/matchers'
22
24
  require 'genspec/generator_example_group'
23
25
 
24
- Thor::Base.shell = GenSpec::Shell.new
25
-
26
26
  # RSpec 2.0 compat
27
27
  RSpec.configure do |config|
28
28
  config.include GenSpec::GeneratorExampleGroup, :example_group => { :file_path => /spec[\/]generators/ }
29
+
30
+ # Kick off the action wrappers.
31
+ #
32
+ # This has to be deferred until the specs run so that the
33
+ # user has a chance to add custom action modules to the
34
+ # list.
35
+ config.before(:each) do
36
+ if self.class.include?(GenSpec::GeneratorExampleGroup) # if this is a generator spec
37
+ GenSpec::Matchers.add_shorthand_methods(self.class)
38
+ end
39
+ end
29
40
  end
@@ -1,8 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe :my_migration do
4
- it "should run migration template" do
5
- # bug, raising NameError: undefined local variable or method `interceptor'
6
- proc { subject.should generate(:migration_template, "1", "2") }.should_not raise_error(NameError)
3
+ if defined?(Rails)
4
+ describe :my_migration do
5
+ it "should run migration template" do
6
+ # bug, raising NameError: undefined local variable or method `interceptor'
7
+ proc { subject.should generate(:migration_template, "1", "2") }.should_not raise_error(NameError)
8
+ end
7
9
  end
8
10
  end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe :question do
4
+ context "without input" do
5
+ it "should raise an error" do
6
+ proc { subject.should output("Are you a GOD?") }.should raise_error
7
+ end
8
+ end
9
+
10
+ with_input "yes" do
11
+ it "should act upon something" do
12
+ subject.should act_upon("something")
13
+ subject.should output(/Acted upon something/)
14
+ end
15
+
16
+ it "should not raise an error" do
17
+ proc { subject.should output("Good.") }.should_not raise_error
18
+ end
19
+ end
20
+
21
+ with_input "no" do
22
+ it "should act upon something" do
23
+ subject.should act_upon("something")
24
+ subject.should output(/Acted upon something/)
25
+ end
26
+
27
+ it "should not raise an error" do
28
+ proc { subject.should output("You're new around here, aren't you?") }.should_not raise_error
29
+ end
30
+ end
31
+ end
@@ -1,6 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe :test_rails3 do
4
+ within_source_root do
5
+ FileUtils.touch "Gemfile"
6
+ end
7
+
8
+ it "should modify Gemfile" do
9
+ out = ""
10
+ subject.should generate {
11
+ File.read("Gemfile").strip.should_not be_blank
12
+ out.concat File.read("Gemfile")
13
+ }
14
+ out.strip.should == 'source "http://gems.github.com/"'
15
+ end
16
+
4
17
  context "with no options or arguments" do
5
18
  it "should generate a file called default_file" do
6
19
  subject.should generate("default_file")
@@ -43,17 +56,19 @@ describe :test_rails3 do
43
56
  # Rails-specific actions are also working. If they are, it's safe to say custom extensions
44
57
  # will work fine too.
45
58
  it 'should add_source "http://gems.github.com/"' do
46
- subject.should add_source("http://gems.github.com/")
59
+ if defined?(Rails)
60
+ subject.should add_source("http://gems.github.com/")
61
+ end
47
62
  end
48
63
  end
49
64
 
50
65
  with_args '--help' do
51
66
  it "should output usage banner with string" do
52
- subject.should output("rails generate test_rails3 [ARGUMENT1] [options]")
67
+ subject.should output(" test_rails3 [ARGUMENT1]")
53
68
  end
54
69
 
55
70
  it "should output usage banner with regexp" do
56
- subject.should output(/rails generate test_rails3/)
71
+ subject.should output(/ test_rails3 /)
57
72
  end
58
73
  end
59
74
 
data/spec/spec_helper.rb CHANGED
@@ -2,10 +2,26 @@
2
2
  # ./support/generators/**/*_generator.rb and
3
3
  # ./support/rails/generators/**/*_generator.rb
4
4
  $LOAD_PATH.push File.join(File.dirname(__FILE__), "support")
5
- require File.join(File.dirname(__FILE__),"../../../config/environment")
6
- require File.join(File.dirname(__FILE__),"../lib/gen_spec")
7
5
 
8
- if Rails::VERSION::MAJOR < 3
9
- Rails::Generator::Base.append_sources Rails::Generator::PathSource.new(:test,
10
- File.expand_path("../support/generators", __FILE__))
6
+ require 'bundler'
7
+ Bundler.setup
8
+
9
+ if ENV['RAILS']
10
+ require 'rails'
11
+ require 'rails/generators'
12
+ end
13
+
14
+ module CustomActions
15
+ def act_upon(file)
16
+ say "Acted upon #{file}."
17
+ end
11
18
  end
19
+
20
+ if !defined?(Rails)
21
+ require 'thor/group'
22
+ require File.expand_path('support/generators/test_rails3/test_rails3_generator', File.dirname(__FILE__))
23
+ require File.expand_path('support/generators/question/question_generator', File.dirname(__FILE__))
24
+ end
25
+
26
+ require File.join(File.dirname(__FILE__),"../lib/gen_spec")
27
+ GenSpec::Matchers::GenerationMethodMatcher::GENERATION_CLASSES << "CustomActions"
@@ -0,0 +1,18 @@
1
+ base = defined?(Rails) ? Rails::Generators::Base : Thor::Group
2
+
3
+ class Question < base
4
+ include Thor::Actions
5
+ include CustomActions
6
+
7
+ def do_acting
8
+ act_upon "something"
9
+ end
10
+
11
+ def ask_question
12
+ yn = ask "Are you a GOD?"
13
+ case yn.downcase[0]
14
+ when ?y then puts "Oh, uh... Good."
15
+ else puts "You're new around here, aren't you?"
16
+ end
17
+ end
18
+ end
@@ -1,4 +1,8 @@
1
- class TestRails3Generator < Rails::Generators::Base
1
+ base = defined?(Rails) ? Rails::Generators::Base : Thor::Group
2
+
3
+ class TestRails3 < base
4
+ include Thor::Actions
5
+
2
6
  def self.source_root
3
7
  File.expand_path('../templates', __FILE__)
4
8
  end
@@ -18,6 +22,10 @@ class TestRails3Generator < Rails::Generators::Base
18
22
  end
19
23
 
20
24
  def gen_gem_source
21
- add_source "http://gems.github.com/"
25
+ if defined?(Rails)
26
+ add_source "http://gems.github.com/"
27
+ else
28
+ append_file "Gemfile", 'source "http://gems.github.com/"'
29
+ end
22
30
  end
23
31
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genspec
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: true
4
+ hash: 23
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
8
  - 2
8
9
  - 0
9
- - prerails3
10
- - 2
11
- version: 0.2.0.prerails3.2
10
+ version: 0.2.0
12
11
  platform: ruby
13
12
  authors:
14
13
  - Colin MacKenzie IV
@@ -20,38 +19,86 @@ date: 2010-07-08 00:00:00 -04:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
- name: rspec
22
+ name: thor
24
23
  prerelease: false
25
24
  requirement: &id001 !ruby/object:Gem::Requirement
26
25
  none: false
27
26
  requirements:
28
- - - ">="
27
+ - - ~>
29
28
  - !ruby/object:Gem::Version
29
+ hash: 43
30
30
  segments:
31
- - 2
32
31
  - 0
33
- - 0
34
- - beta
35
32
  - 14
36
- version: 2.0.0.beta.14
33
+ - 6
34
+ version: 0.14.6
37
35
  type: :runtime
38
36
  version_requirements: *id001
39
37
  - !ruby/object:Gem::Dependency
40
- name: sc-core-ext
38
+ name: rspec
41
39
  prerelease: false
42
40
  requirement: &id002 !ruby/object:Gem::Requirement
43
41
  none: false
44
42
  requirements:
45
- - - ">="
43
+ - - ~>
46
44
  - !ruby/object:Gem::Version
45
+ hash: 23
46
+ segments:
47
+ - 2
48
+ - 6
49
+ - 0
50
+ version: 2.6.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: sc-core-ext
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 29
47
62
  segments:
48
63
  - 1
49
64
  - 2
50
65
  - 1
51
66
  version: 1.2.1
52
67
  type: :runtime
53
- version_requirements: *id002
54
- description: Simple, expressive Rails 3 generator testing for RSpec. For the Rails 2.3 version, use genspec 0.1.x.
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: i18n
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ hash: 11
78
+ segments:
79
+ - 0
80
+ - 5
81
+ - 0
82
+ version: 0.5.0
83
+ type: :runtime
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: bundler
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - "="
92
+ - !ruby/object:Gem::Version
93
+ hash: 9
94
+ segments:
95
+ - 1
96
+ - 0
97
+ - 15
98
+ version: 1.0.15
99
+ type: :development
100
+ version_requirements: *id005
101
+ description: Simple, expressive Thor and/or Rails 3 generator testing for RSpec. For the Rails 2.3 version, use genspec 0.1.x.
55
102
  email: sinisterchipmunk@gmail.com
56
103
  executables: []
57
104
 
@@ -61,10 +108,15 @@ extra_rdoc_files:
61
108
  - LICENSE
62
109
  - README.rdoc
63
110
  files:
111
+ - .document
112
+ - .gitignore
113
+ - .rspec
114
+ - .travis.yml
115
+ - Gemfile
116
+ - Gemfile.lock
64
117
  - LICENSE
65
118
  - README.rdoc
66
119
  - Rakefile
67
- - VERSION
68
120
  - genspec.gemspec
69
121
  - lib/gen_spec.rb
70
122
  - lib/genspec.rb
@@ -75,16 +127,15 @@ files:
75
127
  - lib/genspec/matchers/output_matcher.rb
76
128
  - lib/genspec/matchers/result_matcher.rb
77
129
  - lib/genspec/shell.rb
78
- - pkg/genspec-0.1.1.gem
79
- - pkg/genspec-0.2.0.prerails3.1.gem
80
- - pkg/genspec-0.2.0.prerails3.2.gem
81
- - spec/environment_spec.rb
130
+ - lib/genspec/version.rb
82
131
  - spec/generators/migration_spec.rb
132
+ - spec/generators/question_spec.rb
83
133
  - spec/generators/test_rails3_spec.rb
84
134
  - spec/rcov.opts
85
135
  - spec/rspec.opts
86
136
  - spec/spec_helper.rb
87
137
  - spec/support/generators/my_migration/my_migration_generator.rb
138
+ - spec/support/generators/question/question_generator.rb
88
139
  - spec/support/generators/test_rails3/USAGE
89
140
  - spec/support/generators/test_rails3/templates/file
90
141
  - spec/support/generators/test_rails3/test_rails3_generator.rb
@@ -102,30 +153,35 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
153
  requirements:
103
154
  - - ">="
104
155
  - !ruby/object:Gem::Version
156
+ hash: 3
105
157
  segments:
106
158
  - 0
107
159
  version: "0"
108
160
  required_rubygems_version: !ruby/object:Gem::Requirement
109
161
  none: false
110
162
  requirements:
111
- - - ">"
163
+ - - ">="
112
164
  - !ruby/object:Gem::Version
165
+ hash: 3
113
166
  segments:
114
- - 1
115
- - 3
116
- - 1
117
- version: 1.3.1
167
+ - 0
168
+ version: "0"
118
169
  requirements: []
119
170
 
120
171
  rubyforge_project:
121
- rubygems_version: 1.3.7
172
+ rubygems_version: 1.5.2
122
173
  signing_key:
123
174
  specification_version: 3
124
- summary: Simple, expressive Rails 3 generator testing for RSpec. For the Rails 2.3 version, use genspec 0.1.x.
175
+ summary: Simple, expressive Thor and/or Rails 3 generator testing for RSpec. For the Rails 2.3 version, use genspec 0.1.x.
125
176
  test_files:
126
- - spec/environment_spec.rb
127
177
  - spec/generators/migration_spec.rb
178
+ - spec/generators/question_spec.rb
128
179
  - spec/generators/test_rails3_spec.rb
180
+ - spec/rcov.opts
181
+ - spec/rspec.opts
129
182
  - spec/spec_helper.rb
130
183
  - spec/support/generators/my_migration/my_migration_generator.rb
184
+ - spec/support/generators/question/question_generator.rb
185
+ - spec/support/generators/test_rails3/templates/file
131
186
  - spec/support/generators/test_rails3/test_rails3_generator.rb
187
+ - spec/support/generators/test_rails3/USAGE
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.0.prerails3.2
Binary file
Binary file
Binary file
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- # To make sure test environment is loading. Other successful tests will render
4
- # this one redundant, so it's safe to remove.
5
- #
6
- # For those who would flame me, this gem evolved out of a bit of test code that
7
- # was written for another project. Since the test code itself became a gem, I
8
- # didn't necessarily have tests for my tests.
9
- #
10
- # Since I'm starting with a code base before the test environment exists, this
11
- # file merely assures me that the test environment is loading.
12
- #
13
- describe "rails" do
14
- it "should be defined" do
15
- Rails
16
- GenSpec
17
- end
18
- end