crudspec 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock
CHANGED
data/README.markdown
CHANGED
@@ -85,6 +85,28 @@ A controller that would work out of the box would look something like:
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
+
## Options
|
89
|
+
|
90
|
+
### Devise
|
91
|
+
|
92
|
+
If you're using [devise](https://github.com/plataformatec/devise) to authenticate your users, you can easily add
|
93
|
+
that to the spec by using the *devise* option.
|
94
|
+
|
95
|
+
For example, if your Devise model is User, you can call the generator
|
96
|
+
like this:
|
97
|
+
|
98
|
+
rails generate crudspec:spec products_controller --devise=user
|
99
|
+
|
100
|
+
And this will add the following lines to the spec:
|
101
|
+
|
102
|
+
include Devise::TestHelpers
|
103
|
+
|
104
|
+
before(:each) do
|
105
|
+
@user = users(:one) # Replace with whatever mock Factory
|
106
|
+
sign_in @user
|
107
|
+
end
|
108
|
+
|
109
|
+
|
88
110
|
# TODO
|
89
111
|
|
90
112
|
* Option to create a test for Ruby::Test
|
data/lib/crudspec/version.rb
CHANGED
@@ -3,11 +3,14 @@ module Crudspec
|
|
3
3
|
class SpecGenerator < Rails::Generators::Base
|
4
4
|
argument :controller_name, :type => :string, :banner => 'controller_name'
|
5
5
|
source_root File.expand_path("../templates", __FILE__)
|
6
|
+
desc "Create a RSpec spec for a CRUD controller"
|
7
|
+
class_option :devise, :desc => "Include steps to authenticate via devise", :type => :string, :banner => "devise_model"
|
6
8
|
|
7
9
|
def generate_spec_file
|
8
10
|
underscored = controller_name.underscore
|
9
11
|
underscored = underscored + '_controller' unless underscored.match(/_controller$/)
|
10
12
|
@class_name = underscored.classify
|
13
|
+
@devise = options[:devise] if options[:devise]
|
11
14
|
|
12
15
|
# Really?
|
13
16
|
@model_name = @class_name.demodulize.match(/(.+)Controller$/)[1].underscore.singularize
|
@@ -2,7 +2,14 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe <%= @class_name %> do
|
4
4
|
fixtures :<%= @model_name.pluralize %>
|
5
|
+
<% if @devise %>
|
6
|
+
include Devise::TestHelpers
|
5
7
|
|
8
|
+
before(:each) do
|
9
|
+
@<%= @devise %> = <%= @devise.pluralize %>(:one) # Replace with whatever mock Factory you're using
|
10
|
+
sign_in @<%= @devise %>
|
11
|
+
end
|
12
|
+
<% end %>
|
6
13
|
describe "GET 'index'" do
|
7
14
|
it "is successful" do
|
8
15
|
get :index
|
@@ -3,19 +3,27 @@ require 'generators/spec_generator'
|
|
3
3
|
|
4
4
|
class SpecGeneratorTest < Rails::Generators::TestCase
|
5
5
|
tests ::Crudspec::Generators::SpecGenerator
|
6
|
-
destination File.expand_path("
|
6
|
+
destination File.expand_path("../../tmp", File.dirname(__FILE__))
|
7
7
|
setup :prepare_destination
|
8
|
+
teardown :prepare_destination
|
8
9
|
|
9
10
|
test "create the controller files" do
|
10
|
-
run_generator
|
11
|
-
run_generator
|
12
|
-
run_generator
|
13
|
-
run_generator
|
11
|
+
run_generator %w(admin/coupons_controller)
|
12
|
+
run_generator %w(admin/discounts)
|
13
|
+
run_generator %w(Admin::Products)
|
14
|
+
run_generator %w(Admin::ClientsController)
|
14
15
|
|
15
16
|
assert_file 'spec/controllers/admin/coupons_controller_spec.rb'
|
16
17
|
assert_file 'spec/controllers/admin/discounts_controller_spec.rb'
|
17
18
|
assert_file 'spec/controllers/admin/products_controller_spec.rb'
|
18
19
|
assert_file 'spec/controllers/admin/clients_controller_spec.rb'
|
19
20
|
end
|
21
|
+
|
22
|
+
test "devise option" do
|
23
|
+
run_generator %w(admin/secrets_controller --devise=user)
|
24
|
+
|
25
|
+
assert_file 'spec/controllers/admin/secrets_controller_spec.rb', /sign_in @user/
|
26
|
+
assert_file 'spec/controllers/admin/secrets_controller_spec.rb', /include Devise::TestHelpers/
|
27
|
+
end
|
20
28
|
end
|
21
29
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crudspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David Padilla
|