/
command_issues_spec.rb
97 lines (84 loc) · 2.92 KB
/
command_issues_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require File.expand_path("../command_helper", __FILE__)
describe "github issues" do
include CommandHelper
specify "issues without args should show help" do
running :issues do
setup_url_for
stdout.should == <<-EOS.gsub(/^ /, '')
You have to provide a command :
open - shows open tickets for this project
closed - shows closed tickets for this project
--user=<username> - show issues from <username>'s repository
--after=<date> - only show issues updated after <date>
EOS
end
end
specify "issues web opens the project's issues page" do
running :issues, "open" do
setup_url_for
mock_issues_for "open"
stdout.should == <<-EOS.gsub(/^ /, '')
-----
Issue #1 (0 votes): members.json 500 error
* Opened about 10 hours ago by bug_finder
* Last updated 5 minutes ago
I have a nasty bug.
-----
EOS
end
end
specify "issues web closed the project's issues page" do
running :issues, "closed" do
setup_url_for
mock_issues_for "closed"
stdout.should == <<-EOS.gsub(/^ /, '')
-----
Issue #1 (0 votes): members.json 500 error
* Opened about 10 hours ago by bug_finder
* Closed 5 minutes ago
* Last updated 5 minutes ago
I have a nasty bug.
-----
EOS
end
end
specify "issues web opens the project's issues page" do
running :issues, "web" do
setup_url_for
@helper.should_receive(:open).once.with("https://github.com/user/project/issues")
end
end
specify "issues web <user> opens the project's issues page for a user repo" do
running :issues, "web", "drnic" do
setup_url_for
@helper.should_receive(:open).once.with("https://github.com/drnic/project/issues")
end
end
class CommandHelper::Runner
def mock_issues_for(state = "open", options = {})
options[:updated_at] = 5.minutes.ago
options[:closed_at] = 5.minutes.ago
options[:created_at] = 10.hours.ago
options[:user] = "user"
options[:project] = "project"
yaml = <<-YAML.gsub(/^ /, '')
---
issues:
- number: 1
votes: 0
created_at: #{options[:created_at].strftime("%Y-%m-%d %H:%M:%S %z")}
body: |-
I have a nasty bug.
title: members.json 500 error
updated_at: #{options[:updated_at].strftime("%Y-%m-%d %H:%M:%S %z")}
#{"closed_at: #{options[:closed_at].strftime("%Y-%m-%d %H:%M:%S %z")}" if state == "closed"}
user: bug_finder
labels: []
state: #{state}
YAML
api_url = "https://github.com/api/v2/yaml/issues/list/#{options[:user]}/#{options[:project]}/#{state}"
@command.should_receive(:open).with(api_url).and_return(yaml)
end
end
end