rspec-cells 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.textile CHANGED
@@ -1,3 +1,7 @@
1
+ h2. 0.1.5
2
+
3
+ * Fixed generated test for namespaced cells.
4
+
1
5
  h2. 0.1.4
2
6
 
3
7
  * Another maintenance release since we broke the gem with the last release :-)
@@ -5,8 +5,12 @@ module Rspec
5
5
  class CellGenerator < ::Cells::Generators::Base
6
6
  source_root File.expand_path('../templates', __FILE__)
7
7
 
8
+ def cell_name
9
+ class_path.empty? ? ":#{file_path}" : %{"#{file_path}"}
10
+ end
11
+
8
12
  def create_cell_spec_file
9
- template "cell_spec.erb", File.join("spec/cells/#{file_name}_cell_spec.rb")
13
+ template "cell_spec.erb", File.join("spec/cells/#{file_path}_cell_spec.rb")
10
14
  end
11
15
  end
12
16
  end
@@ -1,22 +1,32 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe <%= class_name %>Cell do
4
- context "cell rendering" do
5
- <% for state in actions %>
4
+
5
+ context "cell instance" do
6
+ subject { cell(<%= cell_name %>) }
7
+
8
+ <%- for state in actions -%>
9
+ it { should respond_to(:<%= state %>) }
10
+ <%- end -%>
11
+ end
12
+
13
+ context "cell rendering" do
14
+ <%- actions.each_with_index do |state, index| -%>
6
15
  context "rendering <%= state %>" do
7
- subject { render_cell(:<%= file_name %>, :<%= state %>) }
8
-
16
+ subject { render_cell(<%= cell_name %>, :<%= state %>) }
17
+
18
+ <%- if defined?(Capybara) -%>
19
+ it { should have_selector("h1", :text => "<%= class_name %>#<%= state %>") }
20
+ it { should have_selector("p", :text => "Find me in app/cells/<%= file_path %>/<%= state %>.html") }
21
+ <%- else -%>
9
22
  it { should have_selector("h1", :content => "<%= class_name %>#<%= state %>") }
10
- it { should have_selector("p", :content => "Find me in app/cells/<%= file_name %>/<%= state %>.html") }
23
+ it { should have_selector("p", :content => "Find me in app/cells/<%= file_path %>/<%= state %>.html") }
24
+ <%- end -%>
11
25
  end
12
- <% end %>
13
- end
14
-
26
+ <%- unless index == actions.length - 1 -%>
15
27
 
16
- context "cell instance" do
17
- subject { cell(:<%= file_name %>) }
18
- <% for state in actions %>
19
- it { should respond_to(:<%= state %>) }
20
- <% end %>
28
+ <%- end -%>
29
+ <%- end -%>
21
30
  end
31
+
22
32
  end
@@ -1,6 +1,6 @@
1
1
  module RSpec # :nodoc:
2
2
  module Cells # :nodoc:
3
- VERSION = '0.1.4'
3
+ VERSION = '0.1.5'
4
4
  end
5
5
  end
6
6
 
@@ -13,46 +13,137 @@ describe Rspec::Generators::CellGenerator do
13
13
  test_case.destination_root = DESTINATION_ROOT
14
14
  test_case.generator_class = Rspec::Generators::CellGenerator
15
15
  self.test = test_case.new :wow
16
- test.run_generator %w(Twitter display form)
17
- end
18
-
19
- # Cleanup after we are done testing
20
- after(:all) do
21
- FileUtils.rm_rf(DESTINATION_ROOT)
22
16
  end
23
17
 
24
18
  def t(line_code)
25
19
  Regexp.new(Regexp.escape(line_code))
26
20
  end
27
21
 
28
- it "creates widget spec" do
29
- test.assert_file "spec/cells/twitter_cell_spec.rb", t("require 'spec_helper'")
30
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('describe TwitterCell do')
31
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('context "cell rendering" do')
32
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('end')
33
- end
22
+ context "When defined Capybara" do
23
+ before(:all) do
24
+ class ::Capybara; end
25
+ test.run_generator %w(Twitter display form)
26
+ end
27
+
28
+ after(:all) do
29
+ FileUtils.rm_rf(DESTINATION_ROOT) # Cleanup after we are done testing
30
+ Object.send(:remove_const, :"Capybara")
31
+ end
32
+
33
+ it 'creates respond_to states specs' do
34
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('context "cell instance" do')
35
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('subject { cell(:twitter) }')
36
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('it { should respond_to(:display) }')
37
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('it { should respond_to(:form) }')
38
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('end')
39
+ end
34
40
 
35
- it 'creates display state' do
36
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('context "rendering display" do')
37
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('subject { render_cell(:twitter, :display) }')
38
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('it { should have_selector("h1", :content => "Twitter#display") }')
39
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('it { should have_selector("p", :content => "Find me in app/cells/twitter/display.html") }')
40
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('end')
41
+ it "creates widget spec" do
42
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t("require 'spec_helper'")
43
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('describe TwitterCell do')
44
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('context "cell rendering" do')
45
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('end')
46
+ end
47
+
48
+ it 'creates display state' do
49
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('context "rendering display" do')
50
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('subject { render_cell(:twitter, :display) }')
51
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('it { should have_selector("h1", :text => "Twitter#display") }')
52
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('it { should have_selector("p", :text => "Find me in app/cells/twitter/display.html") }')
53
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('end')
54
+ end
55
+
56
+ it 'creates form state' do
57
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('context "rendering form" do')
58
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('subject { render_cell(:twitter, :form) }')
59
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('it { should have_selector("h1", :text => "Twitter#form") }')
60
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('it { should have_selector("p", :text => "Find me in app/cells/twitter/form.html") }')
61
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('end')
62
+ end
41
63
  end
42
64
 
43
- it 'creates form state' do
44
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('context "rendering form" do')
45
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('subject { render_cell(:twitter, :form) }')
46
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('it { should have_selector("h1", :content => "Twitter#form") }')
47
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('it { should have_selector("p", :content => "Find me in app/cells/twitter/form.html") }')
48
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('end')
65
+ context "When not defined Capybara" do
66
+ before(:all) do
67
+ test.run_generator %w(Twitter display form)
68
+ end
69
+
70
+ after(:all) do
71
+ FileUtils.rm_rf(DESTINATION_ROOT) # Cleanup after we are done testing
72
+ end
73
+
74
+ it 'creates respond_to states specs' do
75
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('context "cell instance" do')
76
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('subject { cell(:twitter) }')
77
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('it { should respond_to(:display) }')
78
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('it { should respond_to(:form) }')
79
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('end')
80
+ end
81
+
82
+ it "creates widget spec" do
83
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t("require 'spec_helper'")
84
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('describe TwitterCell do')
85
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('context "cell rendering" do')
86
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('end')
87
+ end
88
+
89
+ it 'creates display state' do
90
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('context "rendering display" do')
91
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('subject { render_cell(:twitter, :display) }')
92
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('it { should have_selector("h1", :content => "Twitter#display") }')
93
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('it { should have_selector("p", :content => "Find me in app/cells/twitter/display.html") }')
94
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('end')
95
+ end
96
+
97
+ it 'creates form state' do
98
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('context "rendering form" do')
99
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('subject { render_cell(:twitter, :form) }')
100
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('it { should have_selector("h1", :content => "Twitter#form") }')
101
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('it { should have_selector("p", :content => "Find me in app/cells/twitter/form.html") }')
102
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('end')
103
+ end
49
104
  end
50
105
 
51
- it 'creates respond_to states specs' do
52
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('context "cell instance" do ')
53
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('subject { cell(:twitter) } ')
54
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('it { should respond_to(:display) }')
55
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('it { should respond_to(:form) }')
56
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('end')
106
+ context "When uses namespace" do
107
+
108
+ before(:all) do
109
+ test.run_generator %w(Forum::Comment display form)
110
+ end
111
+
112
+ after(:all) do
113
+ FileUtils.rm_rf(DESTINATION_ROOT) # Cleanup after we are done testing
114
+ end
115
+
116
+ GENERATED_FILE = "spec/cells/forum/comment_cell_spec.rb"
117
+
118
+ it 'creates respond_to states specs' do
119
+ test.assert_file GENERATED_FILE, t('context "cell instance" do')
120
+ test.assert_file GENERATED_FILE, t('subject { cell("forum/comment") }')
121
+ test.assert_file GENERATED_FILE, t('it { should respond_to(:display) }')
122
+ test.assert_file GENERATED_FILE, t('it { should respond_to(:form) }')
123
+ test.assert_file GENERATED_FILE, t('end')
124
+ end
125
+
126
+ it "creates widget spec" do
127
+ test.assert_file GENERATED_FILE, t("require 'spec_helper'")
128
+ test.assert_file GENERATED_FILE, t('describe Forum::CommentCell do')
129
+ test.assert_file GENERATED_FILE, t('context "cell rendering" do')
130
+ test.assert_file GENERATED_FILE, t('end')
131
+ end
132
+
133
+ it 'creates display state' do
134
+ test.assert_file GENERATED_FILE, t('context "rendering display" do')
135
+ test.assert_file GENERATED_FILE, t('subject { render_cell("forum/comment", :display) }')
136
+ test.assert_file GENERATED_FILE, t('it { should have_selector("h1", :content => "Forum::Comment#display") }')
137
+ test.assert_file GENERATED_FILE, t('it { should have_selector("p", :content => "Find me in app/cells/forum/comment/display.html") }')
138
+ test.assert_file GENERATED_FILE, t('end')
139
+ end
140
+
141
+ it 'creates form state' do
142
+ test.assert_file GENERATED_FILE, t('context "rendering form" do')
143
+ test.assert_file GENERATED_FILE, t('subject { render_cell("forum/comment", :form) }')
144
+ test.assert_file GENERATED_FILE, t('it { should have_selector("h1", :content => "Forum::Comment#form") }')
145
+ test.assert_file GENERATED_FILE, t('it { should have_selector("p", :content => "Find me in app/cells/forum/comment/form.html") }')
146
+ test.assert_file GENERATED_FILE, t('end')
147
+ end
57
148
  end
58
149
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-cells
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-24 00:00:00.000000000 Z
12
+ date: 2012-10-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties