neverfails 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/HISTORY.md +2 -8
- data/README.md +9 -9
- data/create-grocery.sh +33 -0
- data/lib/neverfails.rb +4 -7
- data/neverfails.gemspec +1 -1
- metadata +4 -3
data/.gitignore
CHANGED
data/HISTORY.md
CHANGED
data/README.md
CHANGED
@@ -128,7 +128,7 @@ Then /^I should see the text \"([^\"]*)\"\$/ do |text|
|
|
128
128
|
end
|
129
129
|
end
|
130
130
|
" > features/step_definitions/fails_steps.rb
|
131
|
-
cucumber
|
131
|
+
cucumber
|
132
132
|
```
|
133
133
|
|
134
134
|
The result is the following, indicating that the *first* step has failed:
|
@@ -144,8 +144,8 @@ To make the first step pass, we need to create an Apple model and store it in th
|
|
144
144
|
|
145
145
|
``` bash
|
146
146
|
rails g model apple
|
147
|
-
rake db:migrate
|
148
|
-
cucumber
|
147
|
+
rake db:migrate RAILS_ENV=test
|
148
|
+
cucumber
|
149
149
|
```
|
150
150
|
|
151
151
|
The result is now the following, indicating that the *second* step has failed:
|
@@ -162,20 +162,20 @@ sed -i '' '
|
|
162
162
|
/get "apples\/index"/ a\
|
163
163
|
match "/apples" => "apples#index"
|
164
164
|
' config/routes.rb
|
165
|
-
cucumber
|
165
|
+
cucumber
|
166
166
|
```
|
167
167
|
|
168
168
|
The result is now the following, indicating that the *third* step has failed:
|
169
169
|
|
170
170
|
```
|
171
|
-
The text "No apples
|
171
|
+
The text "No apples left" was not found in the current page (RSpec::Expectations::ExpectationNotMetError)
|
172
172
|
```
|
173
173
|
|
174
174
|
To make the third step pass, we need to add the text "No apples left" to the page that lists apples:
|
175
175
|
|
176
176
|
``` bash
|
177
177
|
echo "No apples left" >| app/views/apples/index.html.erb
|
178
|
-
cucumber
|
178
|
+
cucumber
|
179
179
|
```
|
180
180
|
|
181
181
|
Step 5 (Run again and see the step pass)
|
@@ -194,8 +194,8 @@ Feature: Apples
|
|
194
194
|
3 steps (3 passed)
|
195
195
|
```
|
196
196
|
|
197
|
-
Neverfails does all of this, so you don't have to
|
198
|
-
|
197
|
+
Neverfails does all of this, so you don't have to
|
198
|
+
=================================================
|
199
199
|
|
200
200
|
The `grocery` example shows that Behaviour-Driven Development is time-consuming even for very small applications, with an empty model and a view showing one sentence.
|
201
201
|
Time is spent watching the tests fail and writing snippets of code that are common to every web application (creating a model, filling view with text and so on).
|
@@ -232,7 +232,7 @@ Step 2 (Run and watch it pass)
|
|
232
232
|
Both the `apples` and the `bananas` scenario can be run with the command:
|
233
233
|
|
234
234
|
``` bash
|
235
|
-
cucumber
|
235
|
+
cucumber
|
236
236
|
```
|
237
237
|
|
238
238
|
The `apples` scenario passes since we already wrote all its required. The `bananas` scenario, though, passes as well:
|
data/create-grocery.sh
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
# This script shows what the latest version neverfails is able to do.
|
3
|
+
# NOTE: For the sake of speed, this script assumes all the required gems
|
4
|
+
# are already installed in the system, so 'bundle install --local' is used.
|
5
|
+
|
6
|
+
# The script creates a Rails application called 'grocery', adds a feature
|
7
|
+
# called banana and runs neverfails to creates the Rails code that generates
|
8
|
+
# the Banana model, controller, index view with a given text and sets the
|
9
|
+
# route to this view
|
10
|
+
|
11
|
+
rails new grocery -JT
|
12
|
+
cd grocery
|
13
|
+
rm public/index.html
|
14
|
+
rm public/images/rails.png
|
15
|
+
echo -e '\ngem "cucumber"' >> Gemfile
|
16
|
+
echo -e '\ngem "cucumber-rails"' >> Gemfile
|
17
|
+
echo -e '\ngem "neverfails"' >> Gemfile
|
18
|
+
bundle install --local
|
19
|
+
rails g cucumber:install
|
20
|
+
echo "require 'cucumber/rails'
|
21
|
+
require 'neverfails'
|
22
|
+
Rails.configuration.cache_classes = false
|
23
|
+
Capybara.default_selector = :css
|
24
|
+
ActionController::Base.allow_rescue = false" >| features/support/env.rb
|
25
|
+
sed -i '' -e's/<<: \*test/<<: *development/' config/database.yml
|
26
|
+
rake db:create
|
27
|
+
cp ../fails_steps.rb features/step_definitions/
|
28
|
+
echo "Feature: Bananas
|
29
|
+
Scenario: No bananas left
|
30
|
+
Given there are no bananas
|
31
|
+
When I browse the list of bananas
|
32
|
+
Then I should see the text \"No bananas left\"" > features/bananas.feature
|
33
|
+
cucumber
|
data/lib/neverfails.rb
CHANGED
@@ -36,17 +36,14 @@ end
|
|
36
36
|
|
37
37
|
def create_missing_page_listing(objects)
|
38
38
|
# Generate the controller
|
39
|
-
|
40
|
-
debugger
|
41
|
-
Rails::Generators.invoke("controller", [objects.classify, "index"])
|
39
|
+
Rails::Generators.invoke("controller", [objects.classify.pluralize, "index"])
|
42
40
|
# Add an extra route match "/models" => "model#index"
|
43
|
-
|
44
|
-
@@missing_view_file = "app/views/#{singular}/index.html.erb"
|
41
|
+
@@missing_view_file = "app/views/#{objects}/index.html.erb"
|
45
42
|
routes_file = 'config/routes.rb'
|
46
43
|
old_routes = File.read(routes_file)
|
47
44
|
File.open(routes_file, "w") do |file|
|
48
|
-
file.puts old_routes.gsub(/get "#{
|
49
|
-
"get \"#{
|
45
|
+
file.puts old_routes.gsub(/get "#{objects}\/index"/,
|
46
|
+
"get \"#{objects}/index\"\nmatch \"/#{objects}\" => \"#{objects}#index\"")
|
50
47
|
end
|
51
48
|
# Reload routes
|
52
49
|
::Rails.application.reload_routes!
|
data/neverfails.gemspec
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'neverfails'
|
6
|
-
s.version = '0.0.
|
6
|
+
s.version = '0.0.2'
|
7
7
|
s.authors = ["Claudio B."]
|
8
8
|
s.email = ["claudiob@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/claudiob/neverfails/tree/rails"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neverfails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Claudio B.
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- MIT-LICENSE
|
63
63
|
- README.md
|
64
64
|
- TODO.md
|
65
|
+
- create-grocery.sh
|
65
66
|
- fails_steps.rb
|
66
67
|
- lib/neverfails.rb
|
67
68
|
- neverfails.gemspec
|