cocot 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog.md ADDED
@@ -0,0 +1,3 @@
1
+ 1.0.0
2
+ -----
3
+ * First release
data/License.md ADDED
@@ -0,0 +1 @@
1
+ This software can be used without monetary charge(free) by the user. Can not be sold, can't get money from it. In case you want to distribute it around please mention me, thank you. IgorJorobus.
data/ReadMe.md ADDED
@@ -0,0 +1,65 @@
1
+ cocot
2
+ =====
3
+
4
+ Sometimes you have a good 'no-rails' idea, and say for yourself: "what a good idea!", what mostly of the time is followed by "okay, but...I can't, I'm in many proyects and I had to create all the folder and files stuff, will take me 15 minutes, or more, so no". You are lazy and you know it. We are great builders of tools which makes our life easy, **cocot** is one of those. **cocot** is a very simple tool that puts you to work in one second, you just have to tell him which will be the name of your proyect and it's done, it creates you the structure of your **BDD** proyect.
5
+
6
+ It supposes that you...
7
+ -----------------------
8
+
9
+ use RSpec and Cucumber for BDD developing, so it creates the conventional files and folders for work with.
10
+
11
+ How can I use it?
12
+ -----------------
13
+
14
+ `cocot NameOfTheProyect` or `cocot "name of the proyect"`. Will build the skeleton in the current working directory, so be aware of be positioned where you want your proyect to be.
15
+
16
+ Gemfile
17
+ -------
18
+
19
+ If you don't have **RSpec** and **Cucumber** installed on your system(or want to update them) you can do it by calling `bundle install` standing on the main folder of your proyect created by **cocot**. If you neither have **bundler** you will need to install it by calling `gem install bundler`.
20
+
21
+ Rakefile
22
+ --------
23
+
24
+ **cocot** packs few pre-defined **rake** tasks:
25
+
26
+ * `rake cucumber` : same like `cucumber`
27
+ * `rake cucumber_wip` : same like `cucumber --format progress --color --wip --tags @wip:3`, specially for order
28
+ * `rake spec` : same like `spec --color`
29
+ * `rake test` : run minitest tests
30
+ * `rake rdoc` : create a doc folder with **RDoc** documentation
31
+
32
+ Skeleton
33
+ --------
34
+
35
+ **cocot** builds:
36
+
37
+ <pre>
38
+ bin\
39
+ | proyect*
40
+ doc\
41
+ features\
42
+ | step_definitions\
43
+ | support\
44
+ | | env.rb
45
+ lib\
46
+ | proyect*
47
+ | proyect*.rb
48
+ spec\
49
+ | proyect*
50
+ | spec_helper.rb
51
+ Changelog.md
52
+ Gemfile
53
+ Gemfile.lock
54
+ License.md
55
+ Rakefile
56
+ ReadMe.md
57
+ </pre>
58
+
59
+ *proyect is replaced by the name of your proyect
60
+
61
+ TODO
62
+ ----
63
+
64
+ * --full option. It builds you extra folders, like "Data", "Share", and "Test".
65
+ * --git-init option. Initialize a git repository(you will need to have **Git** in your system), and stash all the files created by **cocot**.
data/bin/cocot ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ #encoding: utf-8
3
+
4
+ require_relative '../lib/cocot'
@@ -0,0 +1,58 @@
1
+ { :bin/proyectI"Y#!/usr/bin/env ruby
2
+ #encoding: utf-8
3
+
4
+ require_relative '../lib/name_of_the_proyect'
5
+ :ET:features/support/env.rbI"�#encoding: utf-8
6
+
7
+ #if you respect the convention of a Ruby proyect layout then the next lines are fixed
8
+ $LOAD_PATH << File.expand_path('../../../lib', __FILE__)
9
+ require 'name_of_the_proyect'
10
+ ;T:lib/proyect.rbI"#encoding: utf-8
11
+ ;T:spec/spec_helper.rbI"5#encoding: utf-8
12
+
13
+ require 'name_of_the_proyect'
14
+ ;T: GemfileI"csource 'https://rubygems.org'
15
+
16
+ gem 'rspec'
17
+ gem 'cucumber'
18
+ gem 'rake'
19
+ gem 'rdoc'
20
+ gem 'bundler'
21
+ ;T:
22
+
23
+ #necesary for minitest tests
24
+ require 'rake/testtask'
25
+ #necesary for cucumber tests
26
+ require 'cucumber/rake/task'
27
+ #necesary for rspec tests
28
+ require 'rspec/core/rake_task'
29
+
30
+ #################TASKS#######################
31
+
32
+ #to execute minitest tests with `rake test`
33
+ Rake::TestTask.new do |t|
34
+ #search recursively under the folder test for files called test*. You have to create the folder manually.
35
+ t.pattern = 'test/**/test*.rb'
36
+ end
37
+
38
+ #to execute cucumber tests with `rake cucumber`
39
+ Cucumber::Rake::Task.new
40
+
41
+ #to execute cucumber wip(work in progress) with 'rake cucumber_wip'. It will kick you if you are working in more than 3 scenarios
42
+ #remember to tag each wip scenarios with @wip above the Scenario keyword in the implicit *.feature
43
+ desc 'Executes cucumber wip'
44
+ task :cucumber_wip do
45
+ system('cucumber --format progress --color --wip --tags @wip:3')
46
+ end
47
+
48
+ #to execute all RSpec tests with `rake spec`
49
+ RSpec::Core::RakeTask.new do |t|
50
+ #opciones de rspec a correr
51
+ t.rspec_opts = ['--color']
52
+ end
53
+
54
+ desc 'to generate RDoc documentation'
55
+ task :rdoc do
56
+ system('rdoc --all --tab-width=1 --format=darkfish --op=doc --force-output')
57
+ end
58
+ ;T
@@ -0,0 +1,24 @@
1
+ #language: es
2
+
3
+ Característica: cocot construye el esqueleto del proyecto.
4
+
5
+ Con el fin de cumplimentar el objetivo principal de la aplicación,
6
+ como desarrollador,
7
+ quiero poder lograr que cocot construya el esqueleto del nuevo proyecto en la ruta actual desde donde se está ejecutando la aplicación.
8
+
9
+ @wip
10
+ Escenario: genero el árbol de carpetas.
11
+ Dado que el usuario ingresó correctamente el comando para esqueletizar su nuevo proyecto, por ejemplo: "cocot Proyecto",
12
+ Cuando origino sus carpetas,
13
+ Entonces debo encontrar creada una carpeta con nombre "Proyecto",
14
+ #realmente el step definition de la siguiente línea testea que estén todos los archivos también
15
+ Y dentro de ella debo encontrarme con la siguiente estructura de carpetas creadas:
16
+ | bin |
17
+ | lib |
18
+ | lib/Proyecto |
19
+ | spec |
20
+ | spec/Proyecto |
21
+ | features |
22
+ | features/support |
23
+ | features/step_definitions |
24
+ | doc |
@@ -0,0 +1,49 @@
1
+ #encoding: utf-8
2
+
3
+ Dado(/^que el usuario ingresó correctamente el comando para esqueletizar su nuevo proyecto, por ejemplo: "cocot Proyecto",$/) do
4
+ cocot.limpiar_argumentos(['Proyecto'])
5
+ cocot.juzgar_argumentos
6
+ cocot.interrogar_juzgador
7
+ (cocot.instance_variable_get(:@error_existente).should_not be true) && (cocot.instance_variable_get(:@ayuda_invocada).should_not be true)
8
+ end
9
+
10
+ Cuando(/^origino sus carpetas,$/) do
11
+ #si todo andubo bien, en el accionar se genera el esqueleto
12
+ cocot.accionar
13
+ end
14
+
15
+ Entonces(/^debo encontrar creada una carpeta con nombre "Proyecto",$/) do
16
+ Dir.exists?("#{Dir.pwd}/#{nombre_del_proyecto()}").should be true
17
+ end
18
+
19
+ Entonces(/^dentro de ella debo encontrarme con la siguiente estructura de carpetas creadas:$/) do |carpetas|
20
+ viejo_directorio_de_trabajo = Dir.pwd #: String
21
+ #me muevo una carpeta hacia adelante
22
+ Dir.chdir("./#{nombre_del_proyecto()}")
23
+ #tiene que haber lo siguiente
24
+ archivos_y_carpetas = %W{ Changelog.md
25
+ Gemfile
26
+ Gemfile.lock
27
+ License.md
28
+ Rakefile
29
+ ReadMe.md
30
+ bin
31
+ bin/#{nombre_del_proyecto()}
32
+ doc
33
+ features
34
+ features/step_definitions
35
+ features/support
36
+ features/support/env.rb
37
+ lib
38
+ lib/#{nombre_del_proyecto()}
39
+ lib/#{nombre_del_proyecto()}.rb
40
+ spec
41
+ spec/#{nombre_del_proyecto()}
42
+ spec/spec_helper.rb }
43
+
44
+ Dir.glob('**/**/*').sort.should be === archivos_y_carpetas.sort
45
+ #vuelvo al viejo directorio de trabajo
46
+ Dir.chdir('..')
47
+ #elimino todas las carpetas y archivos creados
48
+ FileUtils.remove_dir("./#{nombre_del_proyecto}", true)
49
+ end
@@ -0,0 +1,64 @@
1
+ #encoding: utf-8
2
+
3
+ #hooks del *.feature correspondiente
4
+ Around('@carpeta_existente') do |escenario, bloque|
5
+ directorio_implicito = 'Proyecto'
6
+ unless Dir.exists?(directorio_implicito) then Dir.mkdir(directorio_implicito) end
7
+ bloque.call
8
+ if Dir.exists?(directorio_implicito) then FileUtils.remove_dir(directorio_implicito, true) end
9
+ end
10
+
11
+ Before do |escenario|
12
+ #en el modelo del dominio ::COCOT es utilizada. Apunta a la única instancia Cocot, la aplicación en si.
13
+ ::COCOT = cocot()
14
+ end
15
+
16
+ #definiciones de pasos
17
+ Dado(/^que aún no inicié la aplicación,$/) do
18
+ cocot()
19
+ end
20
+
21
+ Cuando(/^ejecuto el comando: "([^"]*)",$/) do |comando_ejecutado|
22
+ #extirpo la palabra 'cocot' venida del *.feature y otras
23
+ argumentos = comando_ejecutado.split.select {|palabra| (palabra.!=('cocot')) && (palabra.!=('\'\'')) && (palabra.!=('""'))} #: Array
24
+ #le digo a cocot que juzgue los argumentos pasados por el usuario al iniciar la aplicación
25
+ cocot.limpiar_argumentos(argumentos)
26
+ cocot.juzgar_argumentos
27
+ end
28
+
29
+ Entonces(/^debo recibir en consola: "([^"]*)"[.,]$/) do |salida|
30
+ cocot.interrogar_juzgador
31
+ #el atributo salida es un #Array, cada item es un #String
32
+ cocot.instance_variable_get(:@salida).should include(salida.+("\n"))
33
+ end
34
+
35
+ Entonces(/^a continuación: "([^"]*)", terminando el programa.$/) do |salida|
36
+ begin
37
+ cocot.accionar.should raise_error(SystemExit)
38
+ #cucumber falla si algún bloque levanta una excepción y no es rescatada, asi que...
39
+ rescue SystemExit
40
+ end
41
+ end
42
+
43
+ Entonces(/^el programa debe terminarse\.$/) do
44
+ begin
45
+ cocot.accionar.should raise_error(SystemExit)
46
+ #cucumber falla si algún bloque levanta una excepción y no es rescatada, asi que...
47
+ rescue SystemExit
48
+ end
49
+ end
50
+
51
+ Entonces(/^debo recibir en consola información que me ayude a comprender el funcionamiento de cocot,$/) do
52
+ cocot.interrogar_juzgador
53
+ cocot.instance_variable_get(:@ayuda_invocada).should be true
54
+ end
55
+
56
+ Cuando(/^ejecuto el comando: "cocot 'Proyecto Fu Fu'", cocot entiende que el nombre del proyecto será "Proyecto Fu Fu",$/) do
57
+ #le digo a cocot que juzgue los argumentos pasados por el usuario al iniciar la aplicación
58
+ cocot.limpiar_argumentos(['Proyecto Fu Fu'])
59
+ cocot.juzgar_argumentos
60
+ end
61
+
62
+ Dado(/^que existe la carpeta "([^"]*)" en el directorio actual,$/) do |carpeta|
63
+ Dir.exists?(carpeta).should be true
64
+ end
@@ -0,0 +1,14 @@
1
+ #encoding: utf-8
2
+
3
+ module CocotHelpers
4
+
5
+ def cocot
6
+ @cocot ||= Cocot.new
7
+ end
8
+
9
+ def nombre_del_proyecto
10
+ @nombre_del_proyecto ||= cocot.instance_variable_get(:@juzgador_de_argumentos).cual_será_el_nombre_del_proyecto? #: String
11
+ end
12
+ end
13
+
14
+ World(CocotHelpers)
@@ -0,0 +1,8 @@
1
+ #encoding: utf-8
2
+
3
+ require 'fileutils'
4
+
5
+ #si se respeta la convención del esqueleto de un proyecto en Ruby entonces la siguiente línea es fija
6
+ $LOAD_PATH << File.expand_path('../../../lib', __FILE__)
7
+ #esta es variable. Acá va el nombre del archivo dentro de lib/ que va a requerir a todos los demás del código fuente
8
+ require 'cocot'
@@ -0,0 +1,49 @@
1
+ #language: es
2
+
3
+ Característica: el usuario ingresa un comando y obtiene una respuesta.
4
+
5
+ Con el fin de conocer que sucede en la aplicación cuando ingreso determinado comando,
6
+ como usuario,
7
+ quiero poder ingresar un comando y recibir una respuesta.
8
+
9
+ Antecedentes: la aplicación aún no fue iniciada.
10
+ Dado que aún no inicié la aplicación,
11
+
12
+ #Casos erroneos.
13
+
14
+ Esquema del escenario: intento iniciar la aplicación ingresando determinados comandos incorrectos.
15
+ Cuando ejecuto el comando: "<comando>",
16
+ Entonces debo recibir en consola: "<salida>",
17
+ Y el programa debe terminarse.
18
+
19
+ Ejemplos: ingreso comandos incorrectos.
20
+ | comando | salida |
21
+ | cocot | Error: cocot needs to know the name of the further proyect. `cocot '<name_of_the_proyect>'`. |
22
+ | cocot '' | Error: cocot needs to know the name of the further proyect. `cocot '<name_of_the_proyect>'`. |
23
+ | cocot dos argumentos | Error: cocot just need one argument: the name of the further proyect. If its name have more than a word you must put these inside ''. |
24
+ | cocot --help nombre | Error: what do you want to do? invoke the help or skeletonize? You can't do both things. |
25
+ | cocot nombre del proyecto --help | Error: what do you want to do? invoke the help or skeletonize? You can't do both things. |
26
+
27
+ @carpeta_existente
28
+ Escenario: ejecuto "cocot Proyecto" existiendo en el directorio actual una carpeta de nombre "Proyecto".
29
+ Dado que existe la carpeta "Proyecto" en el directorio actual,
30
+ Cuando ejecuto el comando: "cocot Proyecto",
31
+ Entonces debo recibir en consola: "Building skeletal structure for Proyecto.",
32
+ Y a continuación: "Skeletal structure can't be build. There's an existing folder in the working directory called Proyecto.", terminando el programa.
33
+
34
+ #Solicitando ayuda.
35
+
36
+ Escenario: invoco ayuda.
37
+ Cuando ejecuto el comando: "cocot --help",
38
+ Entonces debo recibir en consola información que me ayude a comprender el funcionamiento de cocot,
39
+ Y el programa debe terminarse.
40
+
41
+ #Arrancando el programa satisfactoriamente.
42
+
43
+ Escenario: arranco el programa satisfactoriamente.
44
+ Cuando ejecuto el comando: "cocot ProyectoFu",
45
+ Entonces debo recibir en consola: "Building skeletal structure for ProyectoFu.",
46
+
47
+ Escenario: arranco el programa satisfactoriamente.
48
+ Cuando ejecuto el comando: "cocot 'Proyecto Fu Fu'", cocot entiende que el nombre del proyecto será "Proyecto Fu Fu",
49
+ Entonces debo recibir en consola: "Building skeletal structure for Proyecto Fu Fu.",
data/lib/cocot.rb ADDED
@@ -0,0 +1,30 @@
1
+ #encoding: utf-8
2
+
3
+ #acá se requieren todos los archivos del código fuente, por ejemplo una línea podría ser "require 'cocot/archivo.rb'"...
4
+
5
+ require_relative 'cocot/cocot'
6
+ require_relative 'cocot/juzgador_de_argumentos'
7
+ require_relative 'cocot/salida_estandar'
8
+ require_relative 'cocot/constructor_de_esqueleto'
9
+
10
+ #ejecuto la aplicación
11
+ begin
12
+ #ejecuto lo siguiente solo si este archivo fue ejecutado desde 'cocot'. Evado que cucumber o rspec lo ejecuten.
13
+ if File.basename($0).==('cocot')
14
+ COCOT = Cocot.new
15
+ COCOT.limpiar_argumentos(ARGV)
16
+ COCOT.juzgar_argumentos
17
+ COCOT.interrogar_juzgador
18
+ COCOT.accionar
19
+ end
20
+ rescue => e
21
+ warn('###############################################################################################')
22
+ warn("ATTENTION: An exception of kind #{e.class} was raised by cocot with this message: #{e.message}.")
23
+ warn('This is the backtrace:')
24
+ e.backtrace.each do |trace|
25
+ warn(trace)
26
+ end
27
+ warn('###############################################################################################')
28
+ warn('Please provide me with this message in https://github.com/IgorJorobus/cocot/issues , thank you.')
29
+ warn('###############################################################################################')
30
+ end
@@ -0,0 +1,62 @@
1
+ #encoding: utf-8
2
+
3
+ #Clase principal de la aplicación.
4
+ class Cocot
5
+
6
+ attr_reader :salida
7
+
8
+ def initialize
9
+ @salida = SalidaEstándar.new($stdout)
10
+ end
11
+
12
+ #@param argumentos [Array]. Se quieren limpiar todos aquellos argumentos vacíos, como por ejemplo aquellos que surgen al pasar '' o "" en la línea de comandos.
13
+ def limpiar_argumentos(argumentos)
14
+ @argumentos = argumentos.select {|arg| arg.strip.length.!=(0)} #: Array
15
+ end
16
+
17
+ #@param argumentos [Array].
18
+ def juzgar_argumentos
19
+ @juzgador_de_argumentos = JuzgadorDeArgumentos.new #: JuzgadorDeArgumentos
20
+ @juzgador_de_argumentos.juzgar_argumentos(@argumentos)
21
+ end
22
+
23
+ #Interroga al juzgador de argumentos en búsqueda de saber si hubo algún error en ellos.
24
+ def interrogar_juzgador
25
+ if @juzgador_de_argumentos.hubo_algun_error?
26
+ @error_existente = true
27
+ @salida.escribir(@juzgador_de_argumentos.describime_el_error)
28
+ elsif @juzgador_de_argumentos.fue_la_ayuda_solicitada?
29
+ @ayuda_invocada = true
30
+ mostrar_ayuda_en_pantalla()
31
+ else
32
+ @salida.escribir("Building skeletal structure for #{@nombre_del_proyecto = @juzgador_de_argumentos.cual_será_el_nombre_del_proyecto?}.\n")
33
+ end
34
+ end
35
+
36
+ #El "accionar" de parte del programa se da una sola vez, luego del interrogatorio al juzgador.
37
+ def accionar
38
+ exit(false) if @error_existente
39
+ exit(true) if @ayuda_invocada
40
+ #llegado a este punto se entiende que el usuario ingresó correctamente el comando de inicio, aunqué puede que el constructor de esqueleto encuentre un problema
41
+ unless construir_esqueleto() then exit(false) end
42
+ #todo anduvo bien
43
+ true
44
+ end
45
+
46
+ def construir_esqueleto
47
+ @constructor_de_esqueleto = ConstructorDeEsqueleto.new
48
+ #si la siguiente acción tiene éxito devuelve true, de otra forma false, lo cual quiere decir que hubo un problema
49
+ if @constructor_de_esqueleto.construir_esqueleto(@nombre_del_proyecto)
50
+ @salida.escribir("Structure builded. Have fun developing! :)\n")
51
+ true
52
+ else
53
+ @salida.escribir(@constructor_de_esqueleto.explicar_inconveniente)
54
+ false
55
+ end
56
+ end
57
+
58
+ def mostrar_ayuda_en_pantalla
59
+ msj_de_ayuda = "cocot builds the skeleton layout of your BDD proyects. You just have to give him the name of your proyect like this: `cocot \"name of the proyect\"`.\n"
60
+ @salida.escribir(msj_de_ayuda)
61
+ end
62
+ end
@@ -0,0 +1,80 @@
1
+ #encoding: utf-8
2
+
3
+ #Una instancia de esta clase es la encargada de construir el esqueleto del nuevo proyecto.
4
+ class ConstructorDeEsqueleto
5
+
6
+ attr_reader :inconveniente
7
+
8
+ #todo lo que sea 'proyect' debe ser reemplazado por el nombre original del proyecto
9
+ SUBCARPETAS = %w{bin lib lib/proyect spec spec/proyect features features/support features/step_definitions doc}
10
+ ARCHIVOS = %w{Changelog.md Gemfile Gemfile.lock License.md Rakefile ReadMe.md bin/proyect features/support/env.rb lib/proyect.rb spec/spec_helper.rb}
11
+
12
+ #@param nombre_del_proyecto [String]. @return [TrueClass or FalseClass].
13
+ def construir_esqueleto(nombre_del_proyecto)
14
+ @nombre_del_proyecto = nombre_del_proyecto
15
+ if !(existe_carpeta_de_mismo_nombre_que_este_proyecto_en_el_directorio_actual?)
16
+ crear_carpeta_del_proyecto()
17
+ else
18
+ @inconveniente = "Skeletal structure can't be build. There's an existing folder in the working directory called #{@nombre_del_proyecto}.\n"
19
+ return false
20
+ end
21
+ #me voy a pasar a la carpeta creada
22
+ @directorio_de_trabajo_original = Dir.pwd #: String
23
+ Dir.chdir("./#{@nombre_del_proyecto}")
24
+ #ahí mismo creo el resto de las carpetas
25
+ crear_subcarpetas()
26
+ crear_archivos()
27
+ escribir_archivos()
28
+ #vuelvo al directorio original
29
+ Dir.chdir(@directorio_de_trabajo_original)
30
+ #si todo anduvo bien devuelvo true
31
+ true
32
+ end
33
+
34
+ def crear_carpeta_del_proyecto
35
+ #creo la carpeta principal
36
+ Dir.mkdir(@nombre_del_proyecto)
37
+ #le digo a la aplicación que escriba en la salida un progreso
38
+ ::COCOT.salida.escribir('.')
39
+ end
40
+
41
+ def crear_subcarpetas
42
+ SUBCARPETAS.collect {|carpeta| if carpeta.include?('proyect') then carpeta.sub('proyect', @nombre_del_proyecto) else carpeta end}.each do |carpeta|
43
+ Dir.mkdir(carpeta)
44
+ ::COCOT.salida.escribir('.')
45
+ end
46
+ end
47
+
48
+ def crear_archivos
49
+ ARCHIVOS.collect {|archivo| if archivo.include?('proyect') then archivo.sub('proyect', @nombre_del_proyecto) else archivo end}.each do |archivo|
50
+ File.new(archivo, 'w+').close
51
+ ::COCOT.salida.escribir('.')
52
+ end
53
+ ::COCOT.salida.escribir("\n")
54
+ end
55
+
56
+ def escribir_archivos
57
+ obtener_contenido_de_archivos() #: Hash
58
+ @contenido_de_archivos.each_pair do |nombre_del_archivo, contenido|
59
+ File.open(nombre_del_archivo.to_s.sub('proyect', @nombre_del_proyecto), 'w+b') do |archivo|
60
+ archivo.write(contenido.gsub('name_of_the_proyect', @nombre_del_proyecto))
61
+ end
62
+ end
63
+ end
64
+
65
+ def existe_carpeta_de_mismo_nombre_que_este_proyecto_en_el_directorio_actual?
66
+ Dir.exists?("./#{@nombre_del_proyecto}")
67
+ end
68
+
69
+ def explicar_inconveniente
70
+ @inconveniente || "No hubo inconvenientes.\n"
71
+ end
72
+
73
+ private
74
+
75
+ def obtener_contenido_de_archivos
76
+ File.open(File.expand_path('../../../data/contenido_de_archivos.cocot', __FILE__), 'r+b') do |archivo|
77
+ @contenido_de_archivos = Marshal.load(archivo) #: Hash
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,86 @@
1
+ #encoding: utf-8
2
+
3
+ module COCOT; end
4
+
5
+ COCOT::CONTENIDO_DE_ARCHIVOS = {}
6
+
7
+ COCOT::CONTENIDO_DE_ARCHIVOS[:'bin/proyect'] = \
8
+ <<STR
9
+ #!/usr/bin/env ruby
10
+ #encoding: utf-8
11
+
12
+ require_relative '../lib/name_of_the_proyect'
13
+ STR
14
+
15
+ COCOT::CONTENIDO_DE_ARCHIVOS[:'features/support/env.rb'] = \
16
+ <<STR
17
+ #encoding: utf-8
18
+
19
+ #if you respect the convention of a Ruby proyect layout then the next lines are fixed
20
+ $LOAD_PATH << File.expand_path('../../../lib', __FILE__)
21
+ require 'name_of_the_proyect'
22
+ STR
23
+
24
+ COCOT::CONTENIDO_DE_ARCHIVOS[:'lib/proyect.rb'] = \
25
+ <<STR
26
+ #encoding: utf-8
27
+ STR
28
+
29
+ COCOT::CONTENIDO_DE_ARCHIVOS[:'spec/spec_helper.rb'] = \
30
+ <<STR
31
+ #encoding: utf-8
32
+
33
+ require 'name_of_the_proyect'
34
+ STR
35
+
36
+ COCOT::CONTENIDO_DE_ARCHIVOS[:'Gemfile'] = \
37
+ <<STR
38
+ source 'https://rubygems.org'
39
+
40
+ gem 'rspec'
41
+ gem 'cucumber'
42
+ gem 'rake'
43
+ gem 'rdoc'
44
+ gem 'bundler'
45
+ STR
46
+
47
+ COCOT::CONTENIDO_DE_ARCHIVOS[:'Rakefile'] = \
48
+ <<STR
49
+ #encoding: utf-8
50
+
51
+ #necesary for minitest tests
52
+ require 'rake/testtask'
53
+ #necesary for cucumber tests
54
+ require 'cucumber/rake/task'
55
+ #necesary for rspec tests
56
+ require 'rspec/core/rake_task'
57
+
58
+ #################TASKS#######################
59
+
60
+ #to execute minitest tests with `rake test`
61
+ Rake::TestTask.new do |t|
62
+ #search recursively under the folder test for files called test*. You have to create the folder manually.
63
+ t.pattern = 'test/**/test*.rb'
64
+ end
65
+
66
+ #to execute cucumber tests with `rake cucumber`
67
+ Cucumber::Rake::Task.new
68
+
69
+ #to execute cucumber wip(work in progress) with 'rake cucumber_wip'. It will kick you if you are working in more than 3 scenarios
70
+ #remember to tag each wip scenarios with @wip above the Scenario keyword in the implicit *.feature
71
+ desc 'Executes cucumber wip'
72
+ task :cucumber_wip do
73
+ system('cucumber --format progress --color --wip --tags @wip:3')
74
+ end
75
+
76
+ #to execute all RSpec tests with `rake spec`
77
+ RSpec::Core::RakeTask.new do |t|
78
+ #opciones de rspec a correr
79
+ t.rspec_opts = ['--color']
80
+ end
81
+
82
+ desc 'to generate RDoc documentation'
83
+ task :rdoc do
84
+ system('rdoc --all --tab-width=1 --format=darkfish --op=doc --force-output')
85
+ end
86
+ STR
@@ -0,0 +1,41 @@
1
+ #encoding: utf-8
2
+
3
+ class JuzgadorDeArgumentos
4
+
5
+ ERRORES_CONOCIDOS = {ningun_argumento: "Error: cocot needs to know the name of the further proyect. `cocot '<name_of_the_proyect>'`.\n", \
6
+ dos_o_mas_argumentos_como_nombre: "Error: cocot just need one argument: the name of the further proyect. If its name have more than a word you must put these inside ''.\n", \
7
+ ayuda_y_esqueletizado_invocados_a_la_vez: "Error: what do you want to do? invoke the help or skeletonize? You can't do both things.\n"}
8
+
9
+ #@param argumentos [Array].
10
+ def juzgar_argumentos(argumentos)
11
+ if argumentos.length.==(0)
12
+ @error_presente_en_argumentos = :ningun_argumento #: Symbol
13
+ elsif ((argumentos.length).!=(cantidad_de_argumentos_sin_help = (argumentos.select {|arg| arg.!=('--help')}.length))) && (argumentos.!=(['--help']))
14
+ @error_presente_en_argumentos = :ayuda_y_esqueletizado_invocados_a_la_vez
15
+ elsif cantidad_de_argumentos_sin_help.>(1)
16
+ @error_presente_en_argumentos = :dos_o_mas_argumentos_como_nombre
17
+ elsif argumentos[0].==('--help')
18
+ @ayuda_solicitada = true
19
+ else
20
+ @nombre_del_proyecto = argumentos[0]
21
+ end
22
+ end
23
+
24
+ def hubo_algun_error?
25
+ true if @error_presente_en_argumentos
26
+ end
27
+
28
+ def describime_el_error
29
+ if hubo_algun_error?
30
+ return ERRORES_CONOCIDOS[@error_presente_en_argumentos]
31
+ end
32
+ end
33
+
34
+ def fue_la_ayuda_solicitada?
35
+ if @ayuda_solicitada then true else false end
36
+ end
37
+
38
+ def cual_será_el_nombre_del_proyecto?
39
+ @nombre_del_proyecto || "No fue definido.\n"
40
+ end
41
+ end
@@ -0,0 +1,15 @@
1
+ #encoding: utf-8
2
+
3
+ class SalidaEstándar < Array
4
+
5
+ #@param salida [IO]. Inicializa la salida estándar de la aplicación.
6
+ def initialize(salida)
7
+ @salida = salida
8
+ end
9
+
10
+ #@param texto [String]. Escribe determinado *texto* en la @salida.
11
+ def escribir(texto)
12
+ self.<<(texto)
13
+ @salida.print(texto)
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ #encoding: utf-8
2
+
3
+ require_relative 'contenido_de_archivos'
4
+
5
+ #Clase solo utilizada para el desarrollo de cocot.
6
+ class SalvadorDeContenidos
7
+
8
+ #Genera ./data/contenido_de_archivos.cocot , un archivo binario con el contenido de los contenidos que tendrán los archivos generados por cocot.
9
+ def salvar_contenido_de_archivos
10
+ puts "Creando carpeta data si no existe."
11
+ unless Dir.exists?('data') then Dir.mkdir('data') end
12
+ puts "Creando contenido_de_archivos.cocot."
13
+ File.open('data/contenido_de_archivos.cocot', 'w+b') do |archivo|
14
+ Marshal.dump(COCOT::CONTENIDO_DE_ARCHIVOS, archivo)
15
+ end
16
+ puts "Creado."
17
+ end
18
+ end
19
+
20
+
@@ -0,0 +1,63 @@
1
+ #encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+
6
+ describe Cocot do
7
+
8
+ it 'extrae los argumentos que considera útiles' do
9
+ argv = [' ', 'argumento_1', 'argumento_2']
10
+ subject.limpiar_argumentos(argv).should be == ['argumento_1', 'argumento_2']
11
+ end
12
+
13
+ before(:each) do
14
+ ::COCOT = subject()
15
+ @argv = ['Nombre de la aplicación']
16
+ subject.limpiar_argumentos(@argv)
17
+ end
18
+
19
+ it 'crea un JuzgadorDeArgumentos' do
20
+ subject.juzgar_argumentos
21
+ subject.instance_variable_get(:@juzgador_de_argumentos).should_not be_nil
22
+ end
23
+
24
+ it 'manda a juzgar los argumentos proveidos por el usuario' do
25
+ #si no hay error devuelve el nombre de la aplicación
26
+ subject.juzgar_argumentos.should be @argv[0]
27
+ end
28
+
29
+ it 'interroga al juzgador preguntándole cual fue el resultado del juicio de argumentos' do
30
+ subject.juzgar_argumentos
31
+ subject.interrogar_juzgador
32
+ subject.instance_variable_get(:@salida).should include("Building skeletal structure for Nombre de la aplicación.\n")
33
+ end
34
+
35
+ it 'acciona mediante comenzar a construir el esqueleto si los argumentos fueron correctos' do
36
+ subject.juzgar_argumentos
37
+ subject.interrogar_juzgador
38
+ subject.accionar.should be true
39
+ #elimino la carpeta generada al llamar accionar()
40
+ if Dir.exists?(dir = "./#{@argv[0]}") then FileUtils.remove_dir(dir, true) end
41
+ end
42
+
43
+ before(:each) {}
44
+
45
+ it 'muestra ayuda en pantalla si el usuario hizo correctamente la petición' do
46
+ argv = ['--help']
47
+ subject.limpiar_argumentos(argv)
48
+ subject.juzgar_argumentos
49
+ subject.should_receive(:mostrar_ayuda_en_pantalla)
50
+ subject.interrogar_juzgador
51
+ end
52
+
53
+ it 'acciona mediante salir de la aplicación si los argumentos no fueron correctos' do
54
+ begin
55
+ argv = ['argumentos', 'no', 'correctos']
56
+ subject.limpiar_argumentos(argv)
57
+ subject.juzgar_argumentos
58
+ subject.interrogar_juzgador
59
+ subject.accionar.should raise_error(SystemExit)
60
+ rescue SystemExit
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,70 @@
1
+ #encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+
6
+ describe JuzgadorDeArgumentos do
7
+ describe '#juzgar_argumentos' do
8
+ it 'reconoce si ningún argumento le fue pasado' do
9
+ subject.juzgar_argumentos([]).should be :ningun_argumento
10
+ end
11
+
12
+ it 'reconoce si se intento invocar ayuda y a la vez se pasaron mas argumentos' do
13
+ subject.juzgar_argumentos(['--help', 'Proyecto']).should be :ayuda_y_esqueletizado_invocados_a_la_vez
14
+ end
15
+
16
+ it 'reconoce si se pasaron mas de un argumento como nombre del proyecto' do
17
+ subject.juzgar_argumentos(['Dos', 'Nombres']).should be :dos_o_mas_argumentos_como_nombre
18
+ end
19
+
20
+ it 'reconoce cuando la ayuda fue invocada correctamente' do
21
+ subject.juzgar_argumentos(['--help']).should be true
22
+ end
23
+
24
+ it 'reconoce si no hubo error alguno' do
25
+ subject.juzgar_argumentos(['Proyecto']).should be_an_instance_of(String)
26
+ end
27
+ end
28
+
29
+ context 'luego de juzgar argumentos' do
30
+ it 'sabe si hubo algún error' do
31
+ subject.juzgar_argumentos(['A', 'B'])
32
+ subject.hubo_algun_error?.should be true
33
+ end
34
+
35
+ it 'y describirlo' do
36
+ subject.juzgar_argumentos(['--help', 'A', 'A'])
37
+ subject.describime_el_error.should be_an_instance_of(String)
38
+ end
39
+
40
+ it 'sabe si no lo hubo' do
41
+ subject.juzgar_argumentos(['Nombre'])
42
+ subject.hubo_algun_error?.should be nil
43
+ end
44
+
45
+ it 'si no hubo no puede describirlo' do
46
+ subject.juzgar_argumentos(['Nombre bien pasado'])
47
+ subject.describime_el_error.should be nil
48
+ end
49
+
50
+ it 'responde si la ayuda fue solicitada' do
51
+ subject.juzgar_argumentos(['--help'])
52
+ subject.fue_la_ayuda_solicitada?.should be true
53
+ end
54
+
55
+ it 'o no' do
56
+ subject.juzgar_argumentos(['Nombre'])
57
+ subject.fue_la_ayuda_solicitada?.should be false
58
+ end
59
+
60
+ it 'dice cual es el nombre del proyecto si es que fue definido en el argumento' do
61
+ subject.juzgar_argumentos(['Secreto'])
62
+ expect {subject.cual_será_el_nombre_del_proyecto?}.to be {'Secreto'}
63
+ end
64
+
65
+ it 'si no fue definido lo expresa' do
66
+ subject.juzgar_argumentos([])
67
+ expect {subject.cual_será_el_nombre_del_proyecto?}.to be {'No fue definido'}
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,28 @@
1
+ #encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+
6
+ describe SalidaEstándar do
7
+
8
+ before(:each) do
9
+ @texto = 'texto'
10
+ #emulo $stderr
11
+ @stderr = double('stderr').as_null_object
12
+ end
13
+
14
+ describe '#escribir' do
15
+ it 'escribe texto en $stderr' do
16
+ @stderr.should_receive(:print).with(@texto)
17
+ #creo el subject
18
+ se = SalidaEstándar.new(@stderr)
19
+ se.escribir(@texto)
20
+ end
21
+
22
+ it 'almacena el texto en si misma(es un #Array)' do
23
+ se = SalidaEstándar.new(@stderr)
24
+ se.escribir(@texto)
25
+ se.should include('texto')
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ #encoding: utf-8
2
+
3
+ require 'cocot'
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocot
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Damián M. González
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-27 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Skeleton builder of a new proyect which will be developed with BDD. This
15
+ application build the folders and archives necesary to start developing fast a new
16
+ proyect BDD oriented. For that, it's supposed that will be used Cucumber and RSpec(perhaps
17
+ also minitest). This have no relation with Rails.
18
+ email:
19
+ executables:
20
+ - cocot
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - bin/cocot
25
+ - data/contenido_de_archivos.cocot
26
+ - Changelog.md
27
+ - License.md
28
+ - ReadMe.md
29
+ - features/cocot_construye_esqueleto.feature
30
+ - features/usuario_ingresa_comando.feature
31
+ - features/step_definitions/cocot_construye_esqueleto_steps.rb
32
+ - features/step_definitions/usuario_ingresa_comando_steps.rb
33
+ - features/support/cocot_helpers.rb
34
+ - features/support/env.rb
35
+ - lib/cocot/cocot.rb
36
+ - lib/cocot/constructor_de_esqueleto.rb
37
+ - lib/cocot/contenido_de_archivos.rb
38
+ - lib/cocot/juzgador_de_argumentos.rb
39
+ - lib/cocot/salida_estandar.rb
40
+ - lib/cocot/salvador_de_contenidos.rb
41
+ - lib/cocot.rb
42
+ - spec/cocot/cocot_spec.rb
43
+ - spec/cocot/juzgador_de_argumentos_spec.rb
44
+ - spec/cocot/salida_estandar_spec.rb
45
+ - spec/spec_helper.rb
46
+ homepage: https://github.com/IgorJorobus/cocot
47
+ licenses: []
48
+ post_install_message: You can start to skeletonize your new proyect now!
49
+ rdoc_options:
50
+ - --all
51
+ - --tab-width=1
52
+ - --format=darkfish
53
+ - --op=doc
54
+ - --force-output
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 1.8.24
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Skeleton builder of a new proyect which will be developed with BDD on Windows.
75
+ test_files: []