bell 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/.gitignore +5 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +2 -0
  4. data/Gemfile.lock +47 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.org +128 -0
  7. data/Rakefile +16 -0
  8. data/bell.gemspec +30 -0
  9. data/bin/bell +5 -0
  10. data/features/create_user.feature +16 -0
  11. data/features/full_report.feature +84 -0
  12. data/features/import_public_contacts.feature +20 -0
  13. data/features/import_user_contacts.feature +43 -0
  14. data/features/list_all_contacts.feature +19 -0
  15. data/features/list_user_contacts.feature +27 -0
  16. data/features/list_users.feature +22 -0
  17. data/features/remove_user.feature +21 -0
  18. data/features/rename_user.feature +25 -0
  19. data/features/step_definitions/cli_steps.rb +59 -0
  20. data/features/step_definitions/contact_steps.rb +104 -0
  21. data/features/step_definitions/database_steps.rb +3 -0
  22. data/features/step_definitions/report_steps.rb +17 -0
  23. data/features/step_definitions/user_steps.rb +71 -0
  24. data/features/support/env.rb +65 -0
  25. data/features/user_report.feature +67 -0
  26. data/lib/bell/cli.rb +12 -0
  27. data/lib/bell/commands/command.rb +58 -0
  28. data/lib/bell/commands/contact_command.rb +91 -0
  29. data/lib/bell/commands/implosion_command.rb +14 -0
  30. data/lib/bell/commands/report_command.rb +69 -0
  31. data/lib/bell/commands/user_command.rb +74 -0
  32. data/lib/bell/commands.rb +5 -0
  33. data/lib/bell/csv_parser.rb +52 -0
  34. data/lib/bell/dispatcher.rb +13 -0
  35. data/lib/bell/displayable.rb +13 -0
  36. data/lib/bell/full_report.rb +145 -0
  37. data/lib/bell/handlers/contacts_handler.rb +79 -0
  38. data/lib/bell/handlers/implosions_handler.rb +9 -0
  39. data/lib/bell/handlers/reports_handler.rb +41 -0
  40. data/lib/bell/handlers/users_handler.rb +50 -0
  41. data/lib/bell/handlers.rb +4 -0
  42. data/lib/bell/message.rb +115 -0
  43. data/lib/bell/public_contact.rb +17 -0
  44. data/lib/bell/user.rb +16 -0
  45. data/lib/bell/user_contact.rb +18 -0
  46. data/lib/bell/user_report.rb +88 -0
  47. data/lib/bell/util.rb +31 -0
  48. data/lib/bell.rb +157 -0
  49. data/spec/bell/cli_spec.rb +4 -0
  50. data/spec/bell/commands/command_spec.rb +59 -0
  51. data/spec/bell/commands/contact_command_spec.rb +112 -0
  52. data/spec/bell/commands/implosion_command_spec.rb +31 -0
  53. data/spec/bell/commands/report_command_spec.rb +71 -0
  54. data/spec/bell/commands/user_command_spec.rb +128 -0
  55. data/spec/bell/csv_parser_spec.rb +167 -0
  56. data/spec/bell/dispatcher_spec.rb +4 -0
  57. data/spec/bell/full_report_spec.rb +4 -0
  58. data/spec/bell/handlers/contacts_handler_spec.rb +160 -0
  59. data/spec/bell/handlers/implosions_handler_spec.rb +11 -0
  60. data/spec/bell/handlers/reports_handler_spec.rb +183 -0
  61. data/spec/bell/handlers/users_handler_spec.rb +94 -0
  62. data/spec/bell/public_contact_spec.rb +4 -0
  63. data/spec/bell/user_contact_spec.rb +4 -0
  64. data/spec/bell/user_report_spec.rb +4 -0
  65. data/spec/bell/user_spec.rb +4 -0
  66. data/spec/spec_helper.rb +21 -0
  67. metadata +230 -0
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .bundle
2
+ data/*.db
3
+ TODO.org
4
+ bootstrap.rb
5
+ pkg
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.2@bell --create
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bell (0.0.1)
5
+ embratel (= 1.1.2)
6
+ sequel (= 3.23.0)
7
+ sqlite3-ruby (= 1.3.3)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ builder (3.0.0)
13
+ cucumber (0.10.2)
14
+ builder (>= 2.1.2)
15
+ diff-lcs (>= 1.1.2)
16
+ gherkin (>= 2.3.5)
17
+ json (>= 1.4.6)
18
+ term-ansicolor (>= 1.0.5)
19
+ diff-lcs (1.1.2)
20
+ embratel (1.1.2)
21
+ gherkin (2.3.7)
22
+ json (>= 1.4.6)
23
+ json (1.5.1)
24
+ rake (0.8.7)
25
+ rspec (2.5.0)
26
+ rspec-core (~> 2.5.0)
27
+ rspec-expectations (~> 2.5.0)
28
+ rspec-mocks (~> 2.5.0)
29
+ rspec-core (2.5.1)
30
+ rspec-expectations (2.5.0)
31
+ diff-lcs (~> 1.1.2)
32
+ rspec-mocks (2.5.0)
33
+ sequel (3.23.0)
34
+ sqlite3 (1.3.3)
35
+ sqlite3-ruby (1.3.3)
36
+ sqlite3 (>= 1.3.3)
37
+ term-ansicolor (1.0.5)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ bell!
44
+ bundler (>= 1.0.0)
45
+ cucumber (= 0.10.2)
46
+ rake (= 0.8.7)
47
+ rspec (= 2.5.0)
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Murilo Soares Pereira
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.org ADDED
@@ -0,0 +1,128 @@
1
+ * bell
2
+ Tenha controle sobre as suas faturas de telefone da Embratel.
3
+
4
+ ** Instalando (ainda não disponível)
5
+ #+BEGIN_SRC
6
+ gem install bell
7
+ #+END_SRC
8
+ Você precisa ter o ruby e o rubygems instalados.
9
+
10
+ ** Como Isso Pode Me Ajudar?
11
+ Bell permite que você crie e mantenha usuários e suas listas de contatos.
12
+ Estes dados combinados com um arquivo de fatura da embratel te permitem
13
+ obter todo o tipo de informação.
14
+
15
+ Por exemplo:
16
+ - mostrar quanto um determinado usuário gastou e para quais números ligou
17
+ - mostrar quanto foi gasto em ligações para um determinado número e quanto
18
+ foi gasto em cada uma das ligações
19
+ - montar relatórios completos, que mostram:
20
+ - o valor total da fatura
21
+ - o valor gasto por cada usuário
22
+ - o valor total, e todas as ligações públicas (feitas por mais de um
23
+ usuário)
24
+ - o valor total, e todas as ligações desconhecidas (não presentes em
25
+ nenhuma lista de contatos)
26
+
27
+ ** Como Usar
28
+ *** Criando Usuários
29
+ #+BEGIN_SRC
30
+ $ bell user create joão
31
+ Usuário 'joão' criado.
32
+ #+END_SRC
33
+
34
+ Você agora pode ver o joão na lista de usuários
35
+ #+BEGIN_SRC
36
+ $ bell user list
37
+ joão
38
+ #+END_SRC
39
+
40
+ *** Importando Contatos
41
+ Com o usuário 'joão' criado você pode importar a lista de contatos dele. A
42
+ lista de contatos deve ser um arquivo csv, onde cada linha deste arquivo
43
+ representa um contato, sendo a primeira coluna o nome e a segunda o número
44
+ de telefone.
45
+
46
+ Exemplo:
47
+ #+CAPTION: Lista de contatos
48
+ [[http://content.screencast.com/users/murilasso/folders/Default/media/99ad1dae-ef89-4c8b-9bfe-eeaa7ac5e3aa/2010-10-30-a7e887a6e.png]]
49
+
50
+ Repare que o formato do número de telefone deve ser uma sequência de 10
51
+ dígitos, sendo os dois primeiros o DDD e os oito últimos o número em si.
52
+
53
+ Com um arquivo da lista de contatos, podemos importar estes contatos para
54
+ um usuário
55
+ #+BEGIN_SRC
56
+ $ bell contact import /path/para/lista/de/contatos.csv -u joão
57
+ #+END_SRC
58
+
59
+ Agora ao listar os contatos do joão você pode ver os contatos que acabou
60
+ de importar
61
+ #+BEGIN_SRC
62
+ $ bell contact list -u joão
63
+ Pedro Silva (1111111111)
64
+ Cássio Cunha (2222222222)
65
+ Jorge Montebello (3333333333)
66
+ Julia Gum (4444444444)
67
+ Cecília Fernandes (5555555555)
68
+ Francisco Côco (6666666666)
69
+ #+END_SRC
70
+
71
+ Com um usuário e sua lista de contatos você pode começar
72
+ a visualizar relatórios, usando os arquivos de fatura da Embratel.
73
+
74
+ *** Fatura da Embratel
75
+ A Embratel fornece faturas de conta de telefone em seu
76
+ [[http://fatura.embratel.net.br/embratel/index.html][serviço online]].
77
+ Para extrair informações sobre uma fatura, você precisará do arquivo
78
+ .csv de um dado mês.
79
+ **** Como obter o arquivo da fatura?
80
+ - [[http://fatura.embratel.net.br/embratel/jsp/selectClientRegister.jsp][cadastre-se]] se você não possui uma conta
81
+ - logue no site
82
+ - escolha o mês da fatura
83
+ - vá em 'Opções' e selecione 'Exportar toda a conta'
84
+ - exporte como 'Excel - CSV'
85
+
86
+ Com usuários e suas respectivas listas de contatos criados você pode
87
+ visualizar diversos tipos de relatórios para a fatura de um dado mês.
88
+
89
+ *** Visualizando Relatórios
90
+ Relatório completo
91
+ #+BEGIN_SRC
92
+ $ bell report /path/para/fatura.csv
93
+ #+END_SRC
94
+
95
+ Relatório de usuário
96
+ #+BEGIN_SRC
97
+ $ bell report /path/para/fatura.csv -u joão
98
+ #+END_SRC
99
+
100
+ Relatório de ligação
101
+ #+BEGIN_SRC
102
+ $ bell report /path/para/fatura.csv -n 1111111111
103
+ #+END_SRC
104
+
105
+ ** Para rodar os testes
106
+ *** Pegue o código
107
+ #+BEGIN_SRC
108
+ git clone git://github.com/murilasso/bell.git
109
+ cd bell
110
+ #+END_SRC
111
+
112
+ *** Instale o bundler e as dependências (se já não estiverem instaladas)
113
+ #+BEGIN_SRC
114
+ gem install bundler
115
+ bundle install
116
+ #+END_SRC
117
+
118
+ *** Rode os testes
119
+ #+BEGIN_SRC
120
+ rake
121
+ #+END_SRC
122
+
123
+ ** Autor
124
+ [[http://murilopereira.com][Murilo Pereira]]
125
+
126
+ ** Licença
127
+ Distribuído sob a
128
+ [[http://github.com/murilasso/embratel/blob/master/MIT-LICENSE][licença MIT]].
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'spec/rake/spectask'
5
+ desc "Run RSpec specs"
6
+ Spec::Rake::SpecTask.new('spec') do |t|
7
+ t.spec_opts = %w[--backtrace --colour]
8
+ t.spec_files = FileList['spec/**/*.rb']
9
+ end
10
+
11
+ require 'cucumber/rake/task'
12
+ Cucumber::Rake::Task.new(:features) do |features|
13
+ features.cucumber_opts = "features --format progress"
14
+ end
15
+
16
+ task :default => [:spec, :features]
data/bell.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../lib/bell', __FILE__)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'bell'
7
+ s.version = Bell::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.author = 'Murilo Pereira'
10
+ s.email = 'murilo@murilopereira.com'
11
+ s.homepage = 'https://github.com/murilasso/bell'
12
+ s.summary = 'Tenha controle sobre as suas faturas de telefone da Embratel.'
13
+
14
+ s.required_rubygems_version = '>= 1.3.6'
15
+
16
+ s.add_development_dependency('bundler', '>= 1.0.0')
17
+ s.add_development_dependency('cucumber', '0.10.2')
18
+ s.add_development_dependency('rake', '0.8.7')
19
+ s.add_development_dependency('rspec', '2.5.0')
20
+
21
+ s.add_dependency('embratel', '1.1.2')
22
+ s.add_dependency('fastercsv', '1.5.4') if RUBY_VERSION < '1.9'
23
+ s.add_dependency('sequel', '3.23.0')
24
+ s.add_dependency('sqlite3-ruby', '1.3.3')
25
+
26
+ s.files = `git ls-files`.split("\n")
27
+ s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
28
+ s.require_path = 'lib'
29
+ s.executable = 'bell'
30
+ end
data/bin/bell ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path('../../lib/bell', __FILE__)
4
+
5
+ Bell::CLI.run(ARGV)
@@ -0,0 +1,16 @@
1
+ @no-txn
2
+ Feature: Shell user creates a user
3
+ As a person using the shell
4
+ I want to create users
5
+ In order to associate phone bill calls and contact lists to a name
6
+
7
+ Scenario: When the given user name isn't taken
8
+ Given no user with name "murilo" exists
9
+ When I create a user with name "murilo"
10
+ Then bell should tell me that a user with name "murilo" was created
11
+ And I should have the user "murilo" in the database
12
+
13
+ Scenario: When the given user name isn't taken
14
+ Given a user with name "murilo" exists
15
+ When I create a user with name "murilo"
16
+ Then bell should tell me that the user "murilo" already exists
@@ -0,0 +1,84 @@
1
+ @no-txn
2
+ Feature: Shell user requests a full report
3
+ As a person using the shell
4
+ I want to show full reports
5
+ In order to see how much each user spent on phone calls
6
+
7
+ Scenario: Non-existing file
8
+ When I request a full report using "/non/existent/path"
9
+ Then bell should tell me that "/non/existent/path" does not exist
10
+
11
+ Scenario: Directory
12
+ Given a directory named "tmp"
13
+ When I request a full report using "tmp"
14
+ Then bell should tell me that "tmp" is a directory
15
+
16
+ Scenario: Non CSV file
17
+ Given a file named "non_csv_file.txt" with:
18
+ """
19
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit
20
+ """
21
+ When I request a full report using "non_csv_file.txt"
22
+ Then bell should tell me that "non_csv_file.txt" is not a csv file
23
+
24
+ Scenario: Malformed CSV file
25
+ Given a file named "malformed_csv_file.csv" with:
26
+ """
27
+ "1", 'first"
28
+ """
29
+ When I request a full report using "malformed_csv_file.csv"
30
+ Then bell should tell me that "malformed_csv_file.csv" is a malformed csv file
31
+
32
+ Scenario: Phone bill file with invalid rows
33
+ Given a file named "invalid_rows.csv" with:
34
+ """
35
+ Detalhes da fatura
36
+
37
+ "Seq ","Origem ","Descri��o ","Periodo/Data ","Terminal_Destino ","Local Origem","Local Destino ","Hora Inicio ","Hora Fim ","Imp ","Pais ","Qtde ","Unid ","Valor (R$) "
38
+ 1,"1634125644-FRANQUIA 01 ","04 - LIGACOES DDD PARA CELULARES ","11/08/10 A 99/99/99 ",1993692887,"SCL -SP ","CAS -SP ",02:56:29 AM," ","E "," ",500
39
+ 2,"1634125644-FRANQUIA 01 ","04 - LIGACOES DDD PARA CELULARES ","11/08/10 A 99/99/99 ",1993692887,"SCL -SP ","CAS -SP ",02:59:03 AM," ","E "," ",900,"MIN ",1.3
40
+ 3,"1634125644-FRANQUIA 01 ",
41
+
42
+ """
43
+ When I request a full report using "invalid_rows.csv"
44
+ Then bell should tell me that "invalid_rows.csv" has errors on lines 4, 6
45
+
46
+ Scenario: Valid phone bill file
47
+ Given a user with name "bob" exists
48
+ And a user with name "earl" exists
49
+ And "bob" has a contact with number "1993692887" in his contact list
50
+ And "earl" has a contact with number "1992563321" in his contact list
51
+ And a public contact with number "1634124321" and name "wig"
52
+ And a file named "fatura.csv" with:
53
+ """
54
+ Detalhes da fatura
55
+
56
+ "Seq ","Origem ","Descri��o ","Periodo/Data ","Terminal_Destino ","Local Origem","Local Destino ","Hora Inicio ","Hora Fim ","Imp ","Pais ","Qtde ","Unid ","Valor (R$) "
57
+ 1,"1634125644-FRANQUIA 01 ","04 - LIGACOES DDD PARA CELULARES ","11/08/10 A 99/99/99 ",1993692887,"SCL -SP ","CAS -SP ",02:56:29 AM," ","E "," ",500,"MIN ",0.73
58
+ 2,"1634125644-FRANQUIA 01 ","04 - LIGACOES DDD PARA CELULARES ","11/08/10 A 99/99/99 ",1993692887,"SCL -SP ","CAS -SP ",02:59:03 AM," ","E "," ",900,"MIN ",1.3
59
+ 3,"1634125644-FRANQUIA 01 ","04 - LIGACOES DDD PARA CELULARES ","13/08/10 A 99/99/99 ",1992563321,"SCL -SP ","CAS -SP ",09:07:55 PM," ","E "," ",5800,"MIN ",8.47
60
+ 3,"1634125644-FRANQUIA 01 ","04 - LIGACOES DDD PARA CELULARES ","10/10/10 A 99/99/99 ",1634124321,"SCL -SP ","CAS -SP ",10:10:10 PM," ","E "," ",5800,"MIN ",18.47
61
+ 3,"1634125644-FRANQUIA 01 ","04 - LIGACOES DDD PARA CELULARES ","09/09/09 A 99/99/99 ",1912341234,"SCL -SP ","CAS -SP ",09:09:09 PM," ","E "," ",5800,"MIN ",3.70
62
+ 3,"1634125644-FRANQUIA 01 ","04 - LIGACOES DDD PARA CELULARES ","13/08/10 A 99/99/99 ",,"SCL -SP ","CAS -SP ",09:07:55 PM," ","E "," ",5800,"MIN ",1.11
63
+
64
+ """
65
+ When I request a full report using "fatura.csv"
66
+ Then the output should be:
67
+ """
68
+ [resumo]
69
+ Total: 33.78
70
+ Usuários: 10.50
71
+ Públicas: 18.47
72
+ Desconhecidas: 3.70
73
+ Taxas: 1.11
74
+
75
+ [usuários]
76
+ bob 4.44
77
+ earl 10.88
78
+
79
+ [ligações públicas]
80
+ 1634124321 (wig) 10:10:10 PM 10/10/10 18.47
81
+
82
+ [ligações desconhecidas]
83
+ 1912341234 09:09:09 PM 09/09/09 3.70
84
+ """
@@ -0,0 +1,20 @@
1
+ @no-txn
2
+ Feature: Shell user imports a csv file of public contacts
3
+ As a person using the shell
4
+ I want to import public contacts
5
+ In order to split common phone calls between all users
6
+
7
+ Scenario: Valid contacts file
8
+ Given a file named "public_contacts.csv" with:
9
+ """
10
+ "john",1234123412
11
+ "bob",9876987698
12
+ """
13
+ When I request a public contact import using "public_contacts.csv"
14
+ Then "john" should be in the public contact list
15
+ And "bob" should be in the public contact list
16
+ And the output should be:
17
+ """
18
+ 'john (1234123412)' adicionado à lista de contatos públicos.
19
+ 'bob (9876987698)' adicionado à lista de contatos públicos.
20
+ """
@@ -0,0 +1,43 @@
1
+ @no-txn
2
+ Feature: Shell user imports a csv file of a user's contacts
3
+ As a person using the shell
4
+ I want to import user contacts
5
+ In order to associate phone calls to users
6
+
7
+ Scenario: Non-existing file
8
+ Given a user with name "earl" exists
9
+ When I request a contact import for "earl" using "/non/existant/path"
10
+ Then bell should tell me that "/non/existant/path" does not exist
11
+
12
+ Scenario: Directory
13
+ Given a directory named "tmp"
14
+ And a user with name "earl" exists
15
+ When I request a contact import for "earl" using "tmp"
16
+ Then bell should tell me that "tmp" is a directory
17
+
18
+ Scenario: Invalid contacts file
19
+ Given a user with name "earl" exists
20
+ And a file named "invalid.csv" with:
21
+ """
22
+ "john",1234123412
23
+ "bob
24
+ """
25
+ When I request a contact import for "earl" using "invalid.csv"
26
+ Then bell should tell me that "invalid.csv" is an invalid contacts file
27
+
28
+ Scenario: Valid contacts file
29
+ Given a user with name "earl" exists
30
+ And "earl" has an empty contact list
31
+ And a file named "earl.csv" with:
32
+ """
33
+ "john",1234123412
34
+ "bob",9876987698
35
+ """
36
+ When I request a contact import for "earl" using "earl.csv"
37
+ Then the output should be:
38
+ """
39
+ 'john (1234123412)' adicionado à lista de contatos do usuário 'earl'.
40
+ 'bob (9876987698)' adicionado à lista de contatos do usuário 'earl'.
41
+ """
42
+ And "earl" should have "john" in his contact list
43
+ And "earl" should have "bob" in his contact list
@@ -0,0 +1,19 @@
1
+ @no-txn
2
+ Feature: Shell user lists all contacts
3
+ As a person using the shell
4
+ I want to list all contacts
5
+ In order to see the contacts' names and numbers
6
+
7
+ Scenario: When there are no created contacts
8
+ Given no created contacts
9
+ When I list all contacts
10
+ Then bell should tell me that there are no created contacts
11
+
12
+ Scenario: When there are created contacts
13
+ Given a user with name "murilo" exists
14
+ And a user with name "roberto" exists
15
+ And "murilo" has a contact with name "augusto" and number "1234123412" in his contact list
16
+ And "roberto" has a contact with name "selma" and number "9876987698" in his contact list
17
+ When I list all contacts
18
+ Then bell's output should contain "augusto (1234123412) - murilo"
19
+ And bell's output should contain "selma (9876987698) - roberto"
@@ -0,0 +1,27 @@
1
+ @no-txn
2
+ Feature: Shell user lists a user's contacts
3
+ As a person using the shell
4
+ I want to a user's contacts
5
+ In order to see the contacts' names and numbers
6
+
7
+ Scenario: When there are no contacts created
8
+ Given a user with name "murilo" exists
9
+ And "murilo" has an empty contact list
10
+ When I list the contacts for the user with name "murilo"
11
+ Then bell should tell me that "murilo" has an empty contact list
12
+
13
+ Scenario: When there are contacts created
14
+ Given a user with name "murilo" exists
15
+ And "murilo" has a contact with name "augusto" and number "1234123412" in his contact list
16
+ And "murilo" has a contact with name "roberto" and number "9876987698" in his contact list
17
+ When I list the contacts for the user with name "murilo"
18
+ Then bell's output should contain /augusto (1234123412)/
19
+ And bell's output should contain /roberto (9876987698)/
20
+
21
+ Scenario: When there are contacts created and asked for the CSV format
22
+ Given a user with name "murilo" exists
23
+ And "murilo" has a contact with name "augusto" and number "1234123412" in his contact list
24
+ And "murilo" has a contact with name "roberto" and number "9876987698" in his contact list
25
+ When I list the contacts for the user with name "murilo" in CSV format
26
+ Then bell's output should contain /"augusto",1234123412/
27
+ And bell's output should contain /"roberto",9876987698/
@@ -0,0 +1,22 @@
1
+ @no-txn
2
+ Feature: Shell user lists users
3
+ As a person using the shell
4
+ I want to list users
5
+ In order to know the names I can associate contacts with
6
+
7
+ Scenario: When no users are in the database
8
+ Given no user exists
9
+ When I list all users
10
+ Then bell should tell me that there are no created users
11
+
12
+ Scenario: When there is one user in the database
13
+ Given a user with name "murilo" exists
14
+ When I list all users
15
+ Then bell's output should contain "murilo"
16
+
17
+ Scenario: When there is more than one user in the database
18
+ Given a user with name "murilo" exists
19
+ And a user with name "augusto" exists
20
+ When I list all users
21
+ Then bell's output should contain "murilo"
22
+ And bell's output should contain "augusto"
@@ -0,0 +1,21 @@
1
+ @no-txn
2
+ Feature: Shell user removes a user
3
+ As a person using the shell
4
+ I want to remove users
5
+ In order to keep my database updated
6
+
7
+ Scenario: When the user that doesn't exist
8
+ Given no user with name "murilo" exists
9
+ When I remove the user with name "murilo"
10
+ Then bell should tell me that there is no user with name "murilo"
11
+
12
+ Scenario: When the user exists
13
+ Given a user with name "murilo" exists
14
+ When I remove the user with name "murilo"
15
+ Then bell should tell me that the user "murilo" was removed
16
+
17
+ Scenario: When the user exists and has contacts
18
+ Given a user with name "murilo" exists
19
+ And "murilo" has a contact with name "selma" in his contact list
20
+ When I remove the user with name "murilo"
21
+ Then I should not have a contact with name "selma" in the database
@@ -0,0 +1,25 @@
1
+ @no-txn
2
+ Feature: Shell user renames a user
3
+ As a person using the shell
4
+ I want to rename users
5
+ In order to keep the user base updated
6
+
7
+ Scenario: When there's no user with the source name
8
+ Given no user with name "bob" exists
9
+ And a user with name "john" exists
10
+ When I rename "bob" to "john"
11
+ Then bell should tell me that there is no user with name "bob"
12
+
13
+ Scenario: When there's a user with the source name and a user with the target name
14
+ Given a user with name "bob" exists
15
+ And a user with name "john" exists
16
+ When I rename "bob" to "john"
17
+ Then bell should tell me that the user "john" already exists
18
+
19
+ Scenario: When there's a user with the source name and no user with the target name
20
+ Given a user with name "bob" exists
21
+ And no user with name "john" exists
22
+ When I rename "bob" to "john"
23
+ Then bell should tell me that the user "bob" was renamed to "john"
24
+ And I should have the user "john" in the database
25
+ And I should not have the user "bob" in the database
@@ -0,0 +1,59 @@
1
+ Given /^a directory named "([^"]*)"$/ do |name|
2
+ inside_the_tmp_directory do
3
+ FileUtils.mkdir(name)
4
+ end
5
+ end
6
+
7
+ Given /^a file named "([^"]*)" with:$/ do |file, content|
8
+ inside_the_tmp_directory do
9
+ file = File.new(file, 'w+') << content
10
+ file.flush
11
+ end
12
+ end
13
+
14
+ Then /^bell should tell me that "([^"]*)" does not exist$/ do |path|
15
+ path = File.join(TMP_PATH, path)
16
+ Bell.output.string.chomp.should == Bell::Message.no_such_file_or_directory(path)
17
+ end
18
+
19
+ Then /^bell should tell me that "([^"]*)" is a directory$/ do |path|
20
+ path = File.join(TMP_PATH, path)
21
+ Bell.output.string.chomp.should == Bell::Message.path_is_a_directory(path)
22
+ end
23
+
24
+ Then /^bell should tell me that "([^"]*)" is an invalid contacts file$/ do |path|
25
+ path = File.join(TMP_PATH, path)
26
+ Bell.output.string.chomp.should == Bell::Message.invalid_contacts_file(path)
27
+ end
28
+
29
+ Then /^bell should tell me that "([^"]*)" is not a csv file$/ do |path|
30
+ path = File.join(TMP_PATH, path)
31
+ Bell.output.string.chomp.should == Bell::Message.non_csv_file(path)
32
+ end
33
+
34
+ Then /^bell should tell me that "([^"]*)" has (?:an )?errors? on lines? ((?:\d+, )*(?:\d+))$/ do |path, numbers|
35
+ path = File.join(TMP_PATH, path)
36
+ message = numbers.insert(0, numbers.size == 1 ? 'Erro na linha ' : 'Erro nas linhas ')
37
+ Bell.output.string.chomp.should == Bell::Message.invalid_rows(path, message)
38
+ end
39
+
40
+ Then /^bell should tell me that "([^"]*)" is a malformed csv file$/ do |path|
41
+ path = File.join(TMP_PATH, path)
42
+ Bell.output.string.chomp.should == Bell::Message.malformed_csv_file(path)
43
+ end
44
+
45
+ Then /^bell's output should contain "(.*)"$/ do |text|
46
+ Bell.output.string.should be_include(text)
47
+ end
48
+
49
+ Then /^bell's output should contain \/(.*)\/$/ do |text|
50
+ Bell.output.string.should be_include(text)
51
+ end
52
+
53
+ Then /^the output should be "([^"]*)"$/ do |text|
54
+ Bell.output.string.chomp.should == text
55
+ end
56
+
57
+ Then /^the output should be:$/ do |text|
58
+ Then %{the output should be "#{text}"}
59
+ end