Skip to content

Commit

Permalink
Merge pull request #1052 from rspec/no-monkey-patch-generators
Browse files Browse the repository at this point in the history
Use non-monkey patch describe in generators.
  • Loading branch information
cupakromer committed Jun 1, 2014
2 parents 5674da7 + ca0d249 commit f41788f
Show file tree
Hide file tree
Showing 22 changed files with 33 additions and 33 deletions.
@@ -1,7 +1,7 @@
require 'rails_helper'

<% module_namespacing do -%>
describe <%= class_name %>Controller, :type => :controller do
RSpec.describe <%= class_name %>Controller, :type => :controller do

<% for action in actions -%>
describe "GET '<%= action %>'" do
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rspec/controller/templates/view_spec.rb
@@ -1,5 +1,5 @@
require 'rails_helper'

describe "<%= file_name %>/<%= @action %>.html.<%= options[:template_engine] %>", :type => :view do
RSpec.describe "<%= file_name %>/<%= @action %>.html.<%= options[:template_engine] %>", :type => :view do
pending "add some examples to (or delete) #{__FILE__}"
end
2 changes: 1 addition & 1 deletion lib/generators/rspec/helper/templates/helper_spec.rb
Expand Up @@ -11,7 +11,7 @@
# end
# end
<% module_namespacing do -%>
describe <%= class_name %>Helper, :type => :helper do
RSpec.describe <%= class_name %>Helper, :type => :helper do
pending "add some examples to (or delete) #{__FILE__}"
end
<% end -%>
2 changes: 1 addition & 1 deletion lib/generators/rspec/integration/templates/request_spec.rb
@@ -1,6 +1,6 @@
require 'rails_helper'

describe "<%= class_name.pluralize %>", :type => :request do
RSpec.describe "<%= class_name.pluralize %>", :type => :request do
describe "GET /<%= table_name %>" do
it "works! (now write some real specs)" do
get <%= index_helper %>_path
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rspec/mailer/templates/mailer_spec.rb
@@ -1,7 +1,7 @@
require "rails_helper"

<% module_namespacing do -%>
describe <%= class_name %>, :type => :mailer do
RSpec.describe <%= class_name %>, :type => :mailer do
<% for action in actions -%>
describe "<%= action %>" do
let(:mail) { <%= class_name %>.<%= action %> }
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rspec/model/templates/model_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'

<% module_namespacing do -%>
describe <%= class_name %>, :type => :model do
RSpec.describe <%= class_name %>, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end
<% end -%>
2 changes: 1 addition & 1 deletion lib/generators/rspec/observer/templates/observer_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'

<% module_namespacing do -%>
describe <%= class_name %>Observer, :type => :observer do
RSpec.describe <%= class_name %>Observer, :type => :observer do
pending "add some examples to (or delete) #{__FILE__}"
end
<% end -%>
2 changes: 1 addition & 1 deletion lib/generators/rspec/scaffold/templates/controller_spec.rb
Expand Up @@ -19,7 +19,7 @@
# that an instance is receiving a specific message.

<% module_namespacing do -%>
describe <%= controller_class_name %>Controller, :type => :controller do
RSpec.describe <%= controller_class_name %>Controller, :type => :controller do

# This should return the minimal set of attributes required to create a valid
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rspec/scaffold/templates/edit_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'

<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
describe "<%= ns_table_name %>/edit", :type => :view do
RSpec.describe "<%= ns_table_name %>/edit", :type => :view do
before(:each) do
@<%= ns_file_name %> = assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rspec/scaffold/templates/index_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'

<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
describe "<%= ns_table_name %>/index", :type => :view do
RSpec.describe "<%= ns_table_name %>/index", :type => :view do
before(:each) do
assign(:<%= table_name %>, [
<% [1,2].each_with_index do |id, model_index| -%>
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rspec/scaffold/templates/new_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'

<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
describe "<%= ns_table_name %>/new", :type => :view do
RSpec.describe "<%= ns_table_name %>/new", :type => :view do
before(:each) do
assign(:<%= ns_file_name %>, <%= class_name %>.new(<%= '))' if output_attributes.empty? %>
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rspec/scaffold/templates/routing_spec.rb
@@ -1,7 +1,7 @@
require "rails_helper"

<% module_namespacing do -%>
describe <%= controller_class_name %>Controller, :type => :routing do
RSpec.describe <%= controller_class_name %>Controller, :type => :routing do
describe "routing" do

<% unless options[:singleton] -%>
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rspec/scaffold/templates/show_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'

<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
describe "<%= ns_table_name %>/show", :type => :view do
RSpec.describe "<%= ns_table_name %>/show", :type => :view do
before(:each) do
@<%= ns_file_name %> = assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rspec/view/templates/view_spec.rb
@@ -1,5 +1,5 @@
require 'rails_helper'

describe "<%= file_path %>/<%= @action %>", :type => :view do
RSpec.describe "<%= file_path %>/<%= @action %>", :type => :view do
pending "add some examples to (or delete) #{__FILE__}"
end
9 changes: 4 additions & 5 deletions spec/generators/rspec/controller/controller_generator_spec.rb
Expand Up @@ -19,8 +19,7 @@
describe 'the spec' do
it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/describe PostsController/) }
it { is_expected.to contain(/describe PostsController, :type => :controller/) }
it { is_expected.to contain(/^RSpec.describe PostsController, :type => :controller/) }
end
end
describe 'skipped with a flag' do
Expand Down Expand Up @@ -73,13 +72,13 @@
subject { file('spec/views/posts/index.html.erb_spec.rb') }
it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/describe "posts\/index.html.erb", :type => :view/) }
it { is_expected.to contain(/^RSpec.describe "posts\/index.html.erb", :type => :view/) }
end
describe 'show.html.erb' do
subject { file('spec/views/posts/show.html.erb_spec.rb') }
it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/describe "posts\/show.html.erb", :type => :view/) }
it { is_expected.to contain(/^RSpec.describe "posts\/show.html.erb", :type => :view/) }
end
end
describe 'with haml' do
Expand All @@ -90,7 +89,7 @@
subject { file('spec/views/posts/index.html.haml_spec.rb') }
it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/describe "posts\/index.html.haml", :type => :view/) }
it { is_expected.to contain(/^RSpec.describe "posts\/index.html.haml", :type => :view/) }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/generators/rspec/helper/helper_generator_spec.rb
Expand Up @@ -18,7 +18,7 @@
describe 'the spec' do
it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/describe PostsHelper, :type => :helper/) }
it { is_expected.to contain(/^RSpec.describe PostsHelper, :type => :helper/) }
end
end
describe 'skipped with a flag' do
Expand Down
Expand Up @@ -26,7 +26,7 @@
subject { file('spec/requests/posts_spec.rb') }
it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/describe "Posts", :type => :request/) }
it { is_expected.to contain(/^RSpec.describe "Posts", :type => :request/) }
it { is_expected.to contain(/describe "GET \/posts"/) }
it { is_expected.to contain(/get posts_index_path/) }
end
Expand Down
1 change: 1 addition & 0 deletions spec/generators/rspec/mailer/mailer_generator_spec.rb
Expand Up @@ -17,6 +17,7 @@
end
it { is_expected.to exist }
it { is_expected.to contain(/require "rails_helper"/) }
it { is_expected.to contain(/^RSpec.describe Posts, :type => :mailer/) }
it { is_expected.to contain(/describe "index" do/) }
it { is_expected.to contain(/describe "show" do/) }
end
Expand Down
2 changes: 1 addition & 1 deletion spec/generators/rspec/model/model_generator_spec.rb
Expand Up @@ -27,7 +27,7 @@

it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/describe Posts, :type => :model/) }
it { is_expected.to contain(/^RSpec.describe Posts, :type => :model/) }
end

describe 'the fixtures' do
Expand Down
2 changes: 1 addition & 1 deletion spec/generators/rspec/observer/observer_generator_spec.rb
Expand Up @@ -16,6 +16,6 @@
describe 'the spec' do
it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/describe PostsObserver, :type => :observer/) }
it { is_expected.to contain(/^RSpec.describe PostsObserver, :type => :observer/) }
end
end
14 changes: 7 additions & 7 deletions spec/generators/rspec/scaffold/scaffold_generator_spec.rb
Expand Up @@ -13,7 +13,7 @@
describe 'with no options' do
before { run_generator %w(posts) }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/describe PostsController, :type => :controller/) }
it { is_expected.to contain(/^RSpec.describe PostsController, :type => :controller/) }
end

describe 'with --no-controller_specs' do
Expand All @@ -25,7 +25,7 @@
describe 'namespaced controller spec' do
subject { file('spec/controllers/admin/posts_controller_spec.rb') }
before { run_generator %w(admin/posts) }
it { is_expected.to contain(/describe Admin::PostsController, :type => :controller/)}
it { is_expected.to contain(/^RSpec.describe Admin::PostsController, :type => :controller/)}
end

describe 'view specs' do
Expand All @@ -36,31 +36,31 @@
subject { file("spec/views/posts/edit.html.erb_spec.rb") }
it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/describe "(.*)\/edit", :type => :view/) }
it { is_expected.to contain(/^RSpec.describe "(.*)\/edit", :type => :view/) }
it { is_expected.to contain(/it "renders the edit (.*) form"/) }
end

describe 'index' do
subject { file("spec/views/posts/index.html.erb_spec.rb") }
it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/describe "(.*)\/index", :type => :view/) }
it { is_expected.to contain(/^RSpec.describe "(.*)\/index", :type => :view/) }
it { is_expected.to contain(/it "renders a list of (.*)"/) }
end

describe 'new' do
subject { file("spec/views/posts/new.html.erb_spec.rb") }
it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/describe "(.*)\/new", :type => :view/) }
it { is_expected.to contain(/^RSpec.describe "(.*)\/new", :type => :view/) }
it { is_expected.to contain(/it "renders new (.*) form"/) }
end

describe 'show' do
subject { file("spec/views/posts/show.html.erb_spec.rb") }
it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/describe "(.*)\/show", :type => :view/) }
it { is_expected.to contain(/^RSpec.describe "(.*)\/show", :type => :view/) }
it { is_expected.to contain(/it "renders attributes in <p>"/) }
end
end
Expand Down Expand Up @@ -136,7 +136,7 @@
describe 'with default options' do
before { run_generator %w(posts) }
it { is_expected.to contain(/require "rails_helper"/) }
it { is_expected.to contain(/describe PostsController, :type => :routing/) }
it { is_expected.to contain(/^RSpec.describe PostsController, :type => :routing/) }
it { is_expected.to contain(/describe "routing"/) }
end

Expand Down
6 changes: 3 additions & 3 deletions spec/generators/rspec/view/view_generator_spec.rb
Expand Up @@ -14,7 +14,7 @@
run_generator %w(posts index)
file('spec/views/posts/index.html.erb_spec.rb').tap do |f|
expect(f).to contain(/require 'rails_helper'/)
expect(f).to contain(/describe "posts\/index", :type => :view/)
expect(f).to contain(/^RSpec.describe "posts\/index", :type => :view/)
end
end

Expand All @@ -23,7 +23,7 @@
run_generator %w(admin/posts index)
file('spec/views/admin/posts/index.html.erb_spec.rb').tap do |f|
expect(f).to contain(/require 'rails_helper'/)
expect(f).to contain(/describe "admin\/posts\/index", :type => :view/)
expect(f).to contain(/^RSpec.describe "admin\/posts\/index", :type => :view/)
end
end
end
Expand All @@ -34,7 +34,7 @@
run_generator %w(posts index --template_engine haml)
file('spec/views/posts/index.html.haml_spec.rb').tap do |f|
expect(f).to contain(/require 'rails_helper'/)
expect(f).to contain(/describe "posts\/index", :type => :view/)
expect(f).to contain(/^RSpec.describe "posts\/index", :type => :view/)
end
end
end
Expand Down

0 comments on commit f41788f

Please sign in to comment.