mailmanager 1.0.15 → 1.0.16

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ html/*
4
4
  doc/*
5
5
  results/*
6
6
  mailman
7
+ coverage/*
data/Changelog CHANGED
@@ -1,4 +1,9 @@
1
- Current version is 1.0.15
1
+ Current version is 1.0.16
2
+
3
+ changes since 1.0.15
4
+ - added rubygems-test support -- https://github.com/rubygems/rubygems-test/blob/master/README.txt
5
+ - added a boatload of tests
6
+ - removed some old unused code
2
7
 
3
8
  changes since 1.0.14
4
9
  - added a Cucumber integration test suite
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mailmanager (1.0.15)
4
+ mailmanager (1.0.16)
5
5
  json (~> 1.4.6)
6
6
  open4 (~> 1.0.1)
7
7
 
@@ -45,6 +45,11 @@ GEM
45
45
  ruby-debug-base19 (>= 0.11.19)
46
46
  ruby_core_source (0.1.4)
47
47
  archive-tar-minitar (>= 0.5.2)
48
+ simplecov (0.3.9)
49
+ simplecov-html (>= 0.3.7)
50
+ simplecov-html (0.3.9)
51
+ simplecov-rcov (0.1.2)
52
+ simplecov
48
53
  term-ansicolor (1.0.5)
49
54
 
50
55
  PLATFORMS
@@ -57,3 +62,5 @@ DEPENDENCIES
57
62
  mailmanager!
58
63
  rspec (~> 2.4.0)
59
64
  ruby-debug19
65
+ simplecov
66
+ simplecov-rcov
data/README.rdoc CHANGED
@@ -13,7 +13,7 @@ check your Python version before using this.
13
13
  == Installation
14
14
 
15
15
  gem install mailmanager
16
-
16
+
17
17
  == Basic Usage
18
18
 
19
19
  mm = MailManager.init('/mailman/root')
@@ -93,12 +93,12 @@ of 2.1.x, probably) to run the Cucumber integration tests. Make a symlink to the
93
93
  root directory of your Mailman install in the mailmanager directory. It should be
94
94
  named "mailman". So if you are in the top-level mailmanager directory and your
95
95
  Mailman installation is in /usr/local/mailman, you would run this command:
96
- ln -s /usr/local/mailman mailman
96
+ ln -s /usr/local/mailman mailman
97
97
 
98
98
  Once that's done, you should be able to just run 'cucumber' in the top-level
99
99
  mailmanager directory.
100
100
 
101
- _MAKE SURE THIS IS NOT A MAILMAN INSTALLATION YOU CARE ABOUT!_ The Cucumber test
101
+ <b>MAKE SURE THIS IS NOT A MAILMAN INSTALLATION YOU CARE ABOUT!</b> The Cucumber test
102
102
  suite will start by deleting all mailing lists so it can have a clean slate to
103
103
  test with.
104
104
 
@@ -106,6 +106,9 @@ test with.
106
106
 
107
107
  - Fork on GitHub
108
108
  - Make a new branch
109
+ - Commit your feature addition or bug fix to that branch.
110
+ - Don't mess with Rakefile, version.rb, or Changelog. (If you want to have your own version, that's fine but bump version in its own commit so we can ignore it when we pull.)
111
+ - Add tests for it. This is important so we don't break it in a future version unintentionally.
109
112
  - Push your changes to that branch (i.e. not master)
110
113
  - Make a pull request
111
114
  - Bask in your awesomeness
data/Rakefile CHANGED
@@ -40,3 +40,6 @@ desc "Run all specs"
40
40
  RSpec::Core::RakeTask.new(:spec) do |spec|
41
41
  spec.pattern = 'spec/**/*_spec.rb'
42
42
  end
43
+
44
+ desc "Run tests for rubygems-test"
45
+ task :test => :spec
@@ -0,0 +1,16 @@
1
+ Feature: Deleting a list
2
+ As a developer using MailManager
3
+ In order to delete lists
4
+ I want MailManager to offer this feature
5
+
6
+ Background:
7
+ Given MailManager is initialized on "./mailman"
8
+
9
+ Scenario: Deleting a list
10
+ Given I have a list named "foo"
11
+ When I delete list "foo"
12
+ Then I should have 0 lists
13
+
14
+ Scenario: Deleting a list that doesn't exist
15
+ Given no lists exist
16
+ Then it should raise MailManager::ListNotFoundError when I delete list "foo"
@@ -0,0 +1,31 @@
1
+ Feature: List metadata
2
+
3
+ Background:
4
+ Given MailManager is initialized on "./mailman"
5
+
6
+ Scenario: Getting the info URL
7
+ Given I have a list named "foo"
8
+ When I ask for its info_url
9
+ Then I should get a URL
10
+
11
+ Scenario: Getting the list address
12
+ Given I have a list named "foo"
13
+ When I ask for its address
14
+ Then I should get an email address
15
+
16
+ Scenario: Getting the request email
17
+ Given I have a list named "foo"
18
+ When I ask for its request_email
19
+ Then I should get an email address
20
+
21
+ Scenario: Setting & getting the list description
22
+ Given I have a list named "foo"
23
+ And I set its description to "foo list of fun"
24
+ When I ask for its description
25
+ Then I should get "foo list of fun"
26
+
27
+ Scenario: Setting & getting the subject prefix
28
+ Given I have a list named "foo"
29
+ And I set its subject_prefix to "[Foo List] "
30
+ When I ask for its subject_prefix
31
+ Then I should get "[Foo List] "
@@ -0,0 +1,22 @@
1
+ Feature: List moderators administration
2
+
3
+ Background:
4
+ Given MailManager is initialized on "./mailman"
5
+ Given I have a list named "foo"
6
+
7
+ Scenario: Adding a moderator
8
+ When I add a moderator "me@bar.com"
9
+ Then I should have 1 moderator
10
+
11
+ Scenario: Adding a moderator that already exists
12
+ Given I add a moderator "me@bar.com"
13
+ Then it should raise MailManager::ModeratorAlreadyExistsError when I add a moderator "me@bar.com"
14
+
15
+ Scenario: Deleting a moderator
16
+ Given I add a moderator "me@bar.com"
17
+ When I delete a moderator "me@bar.com"
18
+ Then I should have 0 moderators
19
+
20
+ Scenario: Deleting a moderator that doesn't exist
21
+ Given I add a moderator "other@bar.com"
22
+ Then it should raise MailManager::ModeratorNotFoundError when I delete a moderator "me@bar.com"
@@ -0,0 +1,47 @@
1
+ Given /^I have a list named "([^"]*)"$/ do |list_name|
2
+ Given %{no lists exist}
3
+ When %{I create a new list "#{list_name}"}
4
+ end
5
+
6
+ When /^I create a new list "([^"]*)"$/ do |list_name|
7
+ @list = @mailmanager.create_list(:name => list_name, :admin_email => 'cuke@foo.org', :admin_password => 'greenisgood')
8
+ end
9
+
10
+ When /^I delete list "([^"]*)"$/ do |list_name|
11
+ list = @mailmanager.get_list(list_name)
12
+ list.delete
13
+ end
14
+
15
+ When /^I ask for its (.+)$/ do |attr|
16
+ @attr = @list.send(attr)
17
+ end
18
+
19
+ Then /^I should get a URL$/ do
20
+ @attr.should =~ %r{^http://.*/}
21
+ end
22
+
23
+ Then /^I should get an email address$/ do
24
+ # super basic email regex
25
+ @attr.should =~ %r{^[^@]+@[^\.]+\..+}
26
+ end
27
+
28
+ When /^I add a moderator "([^"]*)"$/ do |mod|
29
+ @list.add_moderator(mod)
30
+ end
31
+
32
+ Then /^I should have (\d+) moderators?$/ do |num|
33
+ @list.should have(num.to_i).moderators
34
+ end
35
+
36
+ When /^I delete a moderator "([^"]*)"$/ do |mod|
37
+ @list.delete_moderator(mod)
38
+ end
39
+
40
+ Given /^I set its (.+?) to "([^"]*)"$/ do |attr,val|
41
+ @list.send("#{attr}=",val)
42
+ end
43
+
44
+ Then /^I should get "([^"]*)"$/ do |val|
45
+ @attr.should == val
46
+ end
47
+
@@ -1,2 +1,7 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', File.dirname(__FILE__))
2
+ if ENV['COVERAGE_REPORT']
3
+ $LOAD_PATH.unshift File.expand_path('../../spec', File.dirname(__FILE__))
4
+ require "mailmanager_simplecov"
5
+ SimpleCov.start 'mailmanager'
6
+ end
2
7
  require "mailmanager"
@@ -9,6 +9,12 @@ module MailManager
9
9
  class ListNameConflictError < StandardError #:nodoc:
10
10
  end
11
11
 
12
+ class ModeratorNotFoundError < StandardError #:nodoc:
13
+ end
14
+
15
+ class ModeratorAlreadyExistsError < StandardError #:nodoc:
16
+ end
17
+
12
18
  class Lib #:nodoc:all
13
19
 
14
20
  def mailmanager
@@ -47,6 +53,7 @@ module MailManager
47
53
 
48
54
  def delete_list(params)
49
55
  params = {:name => params} unless params.respond_to?(:has_key?)
56
+ raise ListNotFoundError, "#{params[:name]} does not exist" unless list_names.include?(params[:name])
50
57
  cmd = :rmlist
51
58
  out = command(cmd, params)
52
59
  parse_output(cmd, out)
@@ -105,7 +112,7 @@ module MailManager
105
112
 
106
113
  def add_moderator(list, email)
107
114
  if moderators(list)['return'].include?(email)
108
- return {'result' => 'already_a_moderator'}
115
+ raise ModeratorAlreadyExistsError, "#{email} is already a moderator of #{list.name}"
109
116
  end
110
117
  cmd = :withlist
111
118
  out = command(cmd, :name => list.name, :wlcmd => 'moderator.append',
@@ -115,7 +122,7 @@ module MailManager
115
122
 
116
123
  def delete_moderator(list, email)
117
124
  unless moderators(list)['return'].include?(email)
118
- return {'result' => 'not_a_moderator'}
125
+ raise ModeratorNotFoundError, "#{email} is not a moderator of #{list.name}"
119
126
  end
120
127
  cmd = :withlist
121
128
  out = command(cmd, :name => list.name, :wlcmd => 'moderator.remove',
@@ -236,15 +243,6 @@ module MailManager
236
243
 
237
244
  def parse_output(mailman_cmd, output)
238
245
  case mailman_cmd
239
- when :newlist
240
- list_name = nil
241
- output.split("\n").each do |line|
242
- if match = /^##\s+(.+?)mailing\s+list\s*$/.match(line)
243
- list_name = match[1]
244
- end
245
- end
246
- raise MailmanExecuteError, "Error getting name of newly created list. Mailman sent:\n#{output}" if list_name.nil?
247
- return_obj = MailManager::List.new(list_name)
248
246
  when :rmlist
249
247
  return_obj = output =~ /Removing list info/
250
248
  when :list_lists
@@ -100,8 +100,8 @@ module MailManager
100
100
  result['result'].to_sym
101
101
  end
102
102
 
103
- # Deletes a moderator from the list. Returns :not_a_moderator if the
104
- # requested deletion isn't a moderator.
103
+ # Deletes a moderator from the list. Raises a ModeratorNotFoundError
104
+ # if the requested deletion isn't a moderator.
105
105
  def delete_moderator(email)
106
106
  result = lib.delete_moderator(self, email)
107
107
  result['result'].to_sym
@@ -1,3 +1,3 @@
1
1
  module MailManager
2
- VERSION = '1.0.15'
2
+ VERSION = '1.0.16'
3
3
  end
data/mailmanager.gemspec CHANGED
@@ -28,4 +28,6 @@ spec = Gem::Specification.new do |s|
28
28
  s.add_development_dependency('ruby-debug19')
29
29
  s.add_development_dependency('ci_reporter')
30
30
  s.add_development_dependency('cucumber')
31
+ s.add_development_dependency('simplecov')
32
+ s.add_development_dependency('simplecov-rcov')
31
33
  end
@@ -80,9 +80,7 @@ EOF
80
80
  subject.should_receive(:run_command).
81
81
  with("#{fake_root}/bin/newlist -q \"bar\" \"foo@bar.baz\" \"qux\" 2>&1", nil).
82
82
  and_return([new_list_return, process])
83
- subject.should_receive(:run_command).
84
- with("#{fake_root}/bin/list_lists 2>&1", nil).
85
- and_return([list_result, process], [list_result_after_create, process])
83
+ subject.stub(:list_names).and_return([],['bar'])
86
84
  subject.create_list(:name => 'bar', :admin_email => 'foo@bar.baz',
87
85
  :admin_password => 'qux')
88
86
  end
@@ -92,9 +90,7 @@ EOF
92
90
  subject.should_receive(:run_command).
93
91
  with("#{fake_root}/bin/newlist -q \"bar\" \"foo@bar.baz\" \"qux\" 2>&1", nil).
94
92
  and_return(["", process])
95
- subject.should_receive(:run_command).
96
- with("#{fake_root}/bin/list_lists 2>&1", nil).
97
- and_return([list_result, process], [list_result_after_create, process])
93
+ subject.stub(:list_names).and_return([],['bar'])
98
94
  subject.create_list(:name => 'bar', :admin_email => 'foo@bar.baz',
99
95
  :admin_password => 'qux')
100
96
  end
@@ -103,14 +99,23 @@ EOF
103
99
  # https://www.pivotaltracker.com/story/show/9421449
104
100
  subject.should_not_receive(:run_command).
105
101
  with("#{fake_root}/bin/newlist -q \"foo\" \"foo@bar.baz\" \"qux\" 2>&1", nil)
106
- subject.should_receive(:run_command).
107
- with("#{fake_root}/bin/list_lists 2>&1", nil).
108
- and_return([list_result, process])
102
+ subject.stub(:list_names).and_return(['foo'])
109
103
  lambda {
110
104
  subject.create_list(:name => 'foo', :admin_email => 'foo@bar.baz',
111
105
  :admin_password => 'qux')
112
106
  }.should raise_error(MailManager::ListNameConflictError)
113
107
  end
108
+
109
+ it "should raise a MailmanExecuteError if the list creation fails on the Mailman side" do
110
+ subject.should_receive(:run_command).
111
+ with("#{fake_root}/bin/newlist -q \"bar\" \"foo@bar.baz\" \"qux\" 2>&1", nil).
112
+ and_return(["", process])
113
+ subject.stub(:get_list).and_raise(MailManager::ListNotFoundError)
114
+ lambda {
115
+ subject.create_list(:name => 'bar', :admin_email => 'foo@bar.baz',
116
+ :admin_password => 'qux')
117
+ }.should raise_error(MailManager::MailmanExecuteError)
118
+ end
114
119
  end
115
120
  end
116
121
 
@@ -119,8 +124,16 @@ EOF
119
124
  subject.should_receive(:run_command).
120
125
  with("#{fake_root}/bin/rmlist \"foo\" 2>&1", nil).
121
126
  and_return(["Removing list info", process])
127
+ subject.stub(:list_names).and_return(['foo'])
122
128
  subject.delete_list('foo')
123
129
  end
130
+
131
+ it "should raise an exception if the list doesn't exist" do
132
+ subject.stub(:list_names).and_return([])
133
+ lambda {
134
+ subject.delete_list('foo')
135
+ }.should raise_error(MailManager::ListNotFoundError)
136
+ end
124
137
  end
125
138
 
126
139
  context "with populated list" do
@@ -187,10 +200,11 @@ EOF
187
200
  test_lib_method(:add_moderator, 'moderator.append', nil, 'foo@bar.com')
188
201
  end
189
202
 
190
- it "should return 'already_a_moderator' if they already a moderator" do
191
- result = {'result' => 'already_a_moderator'}
203
+ it "should raise ModeratorAlreadyExistsError if they already a moderator" do
192
204
  subject.should_receive(:moderators).with(list).and_return({'result' => 'success', 'return' => ['foo@bar.com']})
193
- subject.add_moderator(list, 'foo@bar.com').should == result
205
+ lambda {
206
+ subject.add_moderator(list, 'foo@bar.com')
207
+ }.should raise_error(MailManager::ModeratorAlreadyExistsError)
194
208
  end
195
209
  end
196
210
 
@@ -200,10 +214,11 @@ EOF
200
214
  test_lib_method(:delete_moderator, 'moderator.remove', nil, 'foo@bar.com')
201
215
  end
202
216
 
203
- it "should return 'not_a_moderator' if they are not already a moderator" do
204
- result = {'result' => 'not_a_moderator'}
217
+ it "should raise ModeratorNotFoundError if they are not already a moderator" do
205
218
  subject.should_receive(:moderators).with(list).and_return({'result' => 'success', 'return' => ['other@bar.com']})
206
- subject.delete_moderator(list, 'foo@bar.com').should == result
219
+ lambda {
220
+ subject.delete_moderator(list, 'foo@bar.com')
221
+ }.should raise_error(MailManager::ModeratorNotFoundError)
207
222
  end
208
223
  end
209
224
 
@@ -0,0 +1,21 @@
1
+ require 'simplecov'
2
+ require 'simplecov-rcov'
3
+
4
+ class SimpleCov::Formatter::MergedFormatter
5
+ def format(result)
6
+ SimpleCov::Formatter::HTMLFormatter.new.format(result)
7
+ SimpleCov::Formatter::RcovFormatter.new.format(result)
8
+ end
9
+ end
10
+
11
+ SimpleCov.adapters.define 'mailmanager' do
12
+ add_filter '/spec/'
13
+ add_filter '/features/'
14
+ add_filter '/config/'
15
+ add_filter '/html/'
16
+ add_filter '/mailman/'
17
+ add_filter '/pkg/'
18
+ add_filter '/tasks/'
19
+ add_filter '/results/'
20
+ end
21
+ SimpleCov.formatter = SimpleCov::Formatter::MergedFormatter
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,7 @@
1
- $:.unshift('../lib')
1
+ $:.unshift File.expand_path('../lib', __FILE__)
2
+ if ENV['COVERAGE_REPORT']
3
+ $:.unshift File.expand_path(File.dirname(__FILE__))
4
+ require "mailmanager_simplecov"
5
+ SimpleCov.start 'mailmanager'
6
+ end
2
7
  require 'mailmanager'
3
-
data/tasks/hudson.rake CHANGED
@@ -1,15 +1,33 @@
1
- if ENV['RUBY_ENV'] == 'test'
1
+ if ENV['RUBY_ENV'] == 'test' || ENV['RUBY_ENV'] == 'cucumber'
2
+
3
+ require 'cucumber/rake/task'
2
4
 
3
5
  namespace :hudson do
6
+ def report_path
7
+ "results/features"
8
+ end
9
+
10
+ Cucumber::Rake::Task.new({'cucumber' => [:report_setup, 'setup:coverage']}) do |t|
11
+ t.cucumber_opts = %{--profile default --no-color --format junit --out #{report_path}}
12
+ end
13
+
14
+ task :report_setup do
15
+ rm_rf report_path
16
+ mkdir_p report_path
17
+ end
18
+
4
19
  task :spec => ["hudson:setup:rspec", 'rake:spec']
5
20
 
6
21
  namespace :setup do
22
+ task :coverage do
23
+ ENV["COVERAGE_REPORT"] = "true"
24
+ end
7
25
  task :pre_ci do
8
26
  ENV["CI_REPORTS"] = 'results/rspec/'
9
27
  gem 'ci_reporter'
10
28
  require 'ci/reporter/rake/rspec'
11
29
  end
12
- task :rspec => [:pre_ci, "ci:setup:rspec"]
30
+ task :rspec => [:pre_ci, :coverage, "ci:setup:rspec"]
13
31
  end
14
32
  end
15
33
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 15
9
- version: 1.0.15
8
+ - 16
9
+ version: 1.0.16
10
10
  platform: ruby
11
11
  authors:
12
12
  - Wes Morgan
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-02-01 00:00:00 -05:00
17
+ date: 2011-02-03 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -116,6 +116,32 @@ dependencies:
116
116
  version: "0"
117
117
  type: :development
118
118
  version_requirements: *id007
119
+ - !ruby/object:Gem::Dependency
120
+ name: simplecov
121
+ prerelease: false
122
+ requirement: &id008 !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ type: :development
131
+ version_requirements: *id008
132
+ - !ruby/object:Gem::Dependency
133
+ name: simplecov-rcov
134
+ prerelease: false
135
+ requirement: &id009 !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ segments:
141
+ - 0
142
+ version: "0"
143
+ type: :development
144
+ version_requirements: *id009
119
145
  description: Ruby wrapper library for GNU Mailman's admin functions
120
146
  email: MorganW@dnc.org
121
147
  executables: []
@@ -125,6 +151,7 @@ extensions: []
125
151
  extra_rdoc_files:
126
152
  - README.rdoc
127
153
  files:
154
+ - .gemtest
128
155
  - .gitignore
129
156
  - .rspec
130
157
  - .rvmrc
@@ -136,8 +163,11 @@ files:
136
163
  - Rakefile
137
164
  - config/cucumber.yml
138
165
  - features/create_list.feature
139
- - features/step_definitions/create_list_steps.rb
166
+ - features/delete_list.feature
167
+ - features/list_metadata.feature
168
+ - features/moderators.feature
140
169
  - features/step_definitions/global_steps.rb
170
+ - features/step_definitions/list_steps.rb
141
171
  - features/support/env.rb
142
172
  - lib/mailmanager.rb
143
173
  - lib/mailmanager/lib.rb
@@ -148,6 +178,7 @@ files:
148
178
  - spec/lib/mailmanager/lib_spec.rb
149
179
  - spec/lib/mailmanager/list_spec.rb
150
180
  - spec/lib/mailmanager_spec.rb
181
+ - spec/mailmanager_simplecov.rb
151
182
  - spec/spec_helper.rb
152
183
  - tasks/hudson.rake
153
184
  has_rdoc: true
@@ -186,4 +217,5 @@ test_files:
186
217
  - spec/lib/mailmanager/lib_spec.rb
187
218
  - spec/lib/mailmanager/list_spec.rb
188
219
  - spec/lib/mailmanager_spec.rb
220
+ - spec/mailmanager_simplecov.rb
189
221
  - spec/spec_helper.rb
@@ -1,4 +0,0 @@
1
- When /^I create a new list "([^"]*)"$/ do |list_name|
2
- @mailmanager.create_list(:name => list_name, :admin_email => 'cuke@foo.org', :admin_password => 'greenisgood')
3
- end
4
-