rtrail 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +4 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE +21 -0
  6. data/README.md +96 -0
  7. data/lib/rtrail.rb +19 -0
  8. data/lib/rtrail/api.rb +42 -0
  9. data/lib/rtrail/case.rb +8 -0
  10. data/lib/rtrail/client.rb +113 -0
  11. data/lib/rtrail/entity.rb +65 -0
  12. data/lib/rtrail/exceptions.rb +4 -0
  13. data/lib/rtrail/helpers.rb +32 -0
  14. data/lib/rtrail/plan.rb +7 -0
  15. data/lib/rtrail/project.rb +83 -0
  16. data/lib/rtrail/result.rb +9 -0
  17. data/lib/rtrail/run.rb +39 -0
  18. data/lib/rtrail/section.rb +7 -0
  19. data/lib/rtrail/suite.rb +26 -0
  20. data/lib/rtrail/test.rb +22 -0
  21. data/mock/app.rb +55 -0
  22. data/mock/views/add_result/1.yajl +4 -0
  23. data/mock/views/add_run/1.yajl +7 -0
  24. data/mock/views/error.yajl +3 -0
  25. data/mock/views/get_case/1.yajl +4 -0
  26. data/mock/views/get_cases/1.yajl +3 -0
  27. data/mock/views/get_plan/1.yajl +4 -0
  28. data/mock/views/get_plans/1.yajl +3 -0
  29. data/mock/views/get_project/1.yajl +4 -0
  30. data/mock/views/get_project/2.yajl +4 -0
  31. data/mock/views/get_projects.yajl +4 -0
  32. data/mock/views/get_result/1.yajl +4 -0
  33. data/mock/views/get_results/1.yajl +3 -0
  34. data/mock/views/get_run/1.yajl +7 -0
  35. data/mock/views/get_run/2.yajl +7 -0
  36. data/mock/views/get_runs/1.yajl +4 -0
  37. data/mock/views/get_section/1.yajl +9 -0
  38. data/mock/views/get_section/2.yajl +9 -0
  39. data/mock/views/get_sections/1.yajl +4 -0
  40. data/mock/views/get_suite/1.yajl +6 -0
  41. data/mock/views/get_suite/2.yajl +5 -0
  42. data/mock/views/get_suite/3.yajl +6 -0
  43. data/mock/views/get_suites/1.yajl +4 -0
  44. data/mock/views/get_suites/2.yajl +4 -0
  45. data/mock/views/get_test/1.yajl +4 -0
  46. data/mock/views/get_test/2.yajl +4 -0
  47. data/mock/views/get_tests/1.yajl +5 -0
  48. data/rtrail.gemspec +41 -0
  49. data/spec/api_spec.rb +46 -0
  50. data/spec/case_spec.rb +12 -0
  51. data/spec/client_spec.rb +43 -0
  52. data/spec/entity_spec.rb +12 -0
  53. data/spec/helpers_spec.rb +52 -0
  54. data/spec/plan_spec.rb +12 -0
  55. data/spec/project_spec.rb +132 -0
  56. data/spec/result_spec.rb +12 -0
  57. data/spec/run_spec.rb +61 -0
  58. data/spec/spec_helper.rb +19 -0
  59. data/spec/suite_spec.rb +29 -0
  60. data/spec/test_spec.rb +34 -0
  61. metadata +258 -0
@@ -0,0 +1,46 @@
1
+ require_relative 'spec_helper'
2
+
3
+ module RTrail
4
+ describe API do
5
+ let(:api) { API.new("http://localhost:8080/", "user", "password") }
6
+
7
+ describe "#initialize" do
8
+ it "initializes the client" do
9
+ expect(api.client).to_not be_nil
10
+ end
11
+ end
12
+
13
+ describe "#projects" do
14
+ it "returns all Projects" do
15
+ projects = api.projects
16
+ expect(projects).to be_an(Array)
17
+ expect(projects.first).to be_a(Project)
18
+ end
19
+ end
20
+
21
+ describe "#project" do
22
+ it "returns a Project instance" do
23
+ project = api.project("First Project")
24
+ expect(project).to be_a(Project)
25
+ expect(project.name).to eq("First Project")
26
+ end
27
+ end
28
+
29
+ describe "#runs" do
30
+ it "returns all Runs for the given Project" do
31
+ runs = api.runs("First Project")
32
+ expect(runs).to be_an(Array)
33
+ expect(runs.first).to be_a(Run)
34
+ end
35
+ end
36
+
37
+ describe "#cases" do
38
+ it "returns all Cases for the given Project and Suite" do
39
+ cases = api.cases("First Project", "First Suite")
40
+ expect(cases).to be_an(Array)
41
+ expect(cases.first).to be_a(Case)
42
+ end
43
+ end
44
+ end
45
+ end # module RTrail
46
+
@@ -0,0 +1,12 @@
1
+ require_relative 'spec_helper'
2
+
3
+ module RTrail
4
+ describe Case do
5
+ context "Class methods" do
6
+ end
7
+
8
+ context "Instance methods" do
9
+ end
10
+ end
11
+ end # module RTrail
12
+
@@ -0,0 +1,43 @@
1
+ require_relative 'spec_helper'
2
+
3
+ module RTrail
4
+ describe Client do
5
+ let(:base_url) { MOCK_APP_URL }
6
+ let(:user) { "somebody" }
7
+ let(:password) { "pa$$w0rd1" }
8
+ let(:client) { Client.new(base_url, user, password) }
9
+
10
+ describe "#initialize" do
11
+ it "sets base_url, user, and password attributes" do
12
+ expect(client.base_url).to eq(base_url)
13
+ expect(client.user).to eq(user)
14
+ expect(client.password).to eq(password)
15
+ end
16
+ end
17
+
18
+ describe "#get" do
19
+ it "sends a GET request" do
20
+ expect(client).to receive(:_request).with(:get, 'get_project/1')
21
+ client.get("get_project/1")
22
+ end
23
+
24
+ it "raises RTrail::Error when GET object is not found" do
25
+ expect {
26
+ client.get("get_project/999")
27
+ }.to raise_error(RTrail::Error)
28
+ end
29
+ end
30
+
31
+ describe "#post" do
32
+ it "sends a POST request" do
33
+ fields = {
34
+ :suite_id => 1,
35
+ :name => "Test Run",
36
+ }
37
+ expect(client).to receive(:_request).with(:post, 'add_run/1', fields)
38
+ client.post("add_run/1", fields)
39
+ end
40
+ end
41
+ end
42
+ end # module RTrail
43
+
@@ -0,0 +1,12 @@
1
+ require_relative 'spec_helper'
2
+
3
+ module RTrail
4
+ describe Entity do
5
+ context "Class methods" do
6
+ end
7
+
8
+ context "Instance methods" do
9
+ end
10
+ end
11
+ end # module RTrail
12
+
@@ -0,0 +1,52 @@
1
+ require_relative 'spec_helper'
2
+ require 'hashie'
3
+
4
+ module RTrail
5
+ describe Helpers do
6
+ class Thing < Hashie::Mash
7
+ include RTrail::Helpers
8
+ end
9
+
10
+ let(:thing) { Thing.new }
11
+
12
+ describe "#is_id?" do
13
+ it "returns true for numeric strings" do
14
+ expect(thing.is_id?('0')).to be true
15
+ expect(thing.is_id?('4')).to be true
16
+ expect(thing.is_id?('117')).to be true
17
+ expect(thing.is_id?('62521')).to be true
18
+ end
19
+
20
+ it "returns false for non-numeric strings" do
21
+ expect(thing.is_id?('')).to be false
22
+ expect(thing.is_id?('x')).to be false
23
+ expect(thing.is_id?('Foobar')).to be false
24
+ expect(thing.is_id?('This sentence no verb')).to be false
25
+ end
26
+ end
27
+
28
+ describe "#path_with_params" do
29
+ it "appends params to the path using TestRail's GET syntax" do
30
+ result = thing.path_with_params("/add_run/1", :suite_id => 4)
31
+ expect(result).to eq("/add_run/1&suite_id=4")
32
+ end
33
+ end
34
+
35
+ describe Helpers::HasCreateTime do
36
+ class Thing < Hashie::Mash
37
+ include RTrail::Helpers::HasCreateTime
38
+ end
39
+
40
+ let(:now) { Time.utc(2014, 'may', 19, 3, 45, 0) }
41
+ let(:thing) { Thing.new(:created_on => now.to_i) }
42
+
43
+ describe "#create_time" do
44
+ it "returns the `created_on` attribute as a Time" do
45
+ expect(thing.create_time).to be_a(Time)
46
+ expect(thing.create_time).to eq(now)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end # module RTrail
52
+
@@ -0,0 +1,12 @@
1
+ require_relative 'spec_helper'
2
+
3
+ module RTrail
4
+ describe Plan do
5
+ context "Class methods" do
6
+ end
7
+
8
+ context "Instance methods" do
9
+ end
10
+ end
11
+ end # module RTrail
12
+
@@ -0,0 +1,132 @@
1
+ require_relative 'spec_helper'
2
+
3
+ module RTrail
4
+ describe Project do
5
+ context "Class methods" do
6
+ describe "#all" do
7
+ it "returns all Projects" do
8
+ projects = Project.all
9
+ expect(projects).to be_an(Array)
10
+ expect(projects.first).to be_a(Project)
11
+ end
12
+ end
13
+
14
+ describe "#by_name" do
15
+ it "returns the Project with the given name if it exists" do
16
+ project = Project.by_name("First Project")
17
+ expect(project).to be_a(Project)
18
+ expect(project).to_not be_nil
19
+ expect(project.name).to eq("First Project")
20
+ end
21
+
22
+ it "raises RTrail::NotFound if no project exists with the given name" do
23
+ expect {
24
+ Project.by_name("Bogus Project Name")
25
+ }.to raise_error(RTrail::NotFound, /not found in TestRail/)
26
+ end
27
+ end
28
+ end
29
+
30
+ context "Instance methods" do
31
+ let(:project1) { Project.new(1) }
32
+ let(:project2) { Project.new(2) }
33
+
34
+ describe "#initialize" do
35
+ it "gets the Project data" do
36
+ expect(project1.id).to eq(1)
37
+ expect(project1.name).to eq("First Project")
38
+ expect(project2.id).to eq(2)
39
+ expect(project2.name).to eq("Second Project")
40
+ end
41
+ end
42
+
43
+ describe "#suite_by_name" do
44
+ it "gets the Suite with the given name if it exists" do
45
+ suite = project1.suite_by_name("First Suite")
46
+ expect(suite).to be_a(Suite)
47
+ expect(suite.name).to eq("First Suite")
48
+ end
49
+
50
+ it "raises RTrail::NotFound if no suite exists with the given name" do
51
+ expect {
52
+ project1.suite_by_name("Third Suite")
53
+ }.to raise_error(RTrail::NotFound, /not found in project/)
54
+ expect {
55
+ project2.suite_by_name("First Suite")
56
+ }.to raise_error(RTrail::NotFound, /not found in project/)
57
+ end
58
+ end
59
+
60
+ describe "#suite" do
61
+ it "returns a Suite by id" do
62
+ suite = project1.suite(1)
63
+ expect(suite).to be_a(Suite)
64
+ expect(suite.id).to eq(1)
65
+ expect(suite.name).to eq("First Suite")
66
+ end
67
+
68
+ it "returns a Suite by name" do
69
+ suite = project1.suite("First Suite")
70
+ expect(suite).to be_a(Suite)
71
+ expect(suite.id).to eq(1)
72
+ expect(suite.name).to eq("First Suite")
73
+ end
74
+ end
75
+
76
+ describe "#suite_id" do
77
+ it "returns the id for a Suite" do
78
+ suite_id = project1.suite_id("First Suite")
79
+ expect(suite_id).to eq(1)
80
+ end
81
+ end
82
+
83
+ describe "#plans" do
84
+ it "returns all Plans in the Project" do
85
+ plans = project1.plans
86
+ expect(plans).to be_an(Array)
87
+ expect(plans.count).to eq(1)
88
+ expect(plans.first).to be_a(Plan)
89
+ end
90
+ end
91
+
92
+ describe "#runs" do
93
+ it "returns all Runs in the Project" do
94
+ runs = project1.runs
95
+ expect(runs.count).to eq(2)
96
+ end
97
+ end
98
+
99
+ describe "#suites" do
100
+ it "returns all Suites in the project" do
101
+ suites = project1.suites
102
+ expect(suites.count).to eq(2)
103
+ end
104
+ end
105
+
106
+ describe "#run" do
107
+ it "returns an existing Run with the same name" do
108
+ run = project1.run("First Suite", "First Run")
109
+ expect(run).to be_a(Run)
110
+ expect(run.id).to eq(1)
111
+ expect(run.suite_id).to eq(1)
112
+ end
113
+
114
+ it "creates a new Run and returns it" do
115
+ run = project1.run("First Suite", "New Run Name")
116
+ expect(run).to be_a(Run)
117
+ expect(run.suite_id).to eq(1)
118
+ end
119
+ end
120
+
121
+ describe "#add_run" do
122
+ it "returns the new Run" do
123
+ run = project1.add_run("First Suite", :name => "New Run Name")
124
+ expect(run).to be_a(Run)
125
+ expect(run.suite_id).to eq(1)
126
+ end
127
+ end
128
+ end
129
+
130
+ end
131
+ end # module RTrail
132
+
@@ -0,0 +1,12 @@
1
+ require_relative 'spec_helper'
2
+
3
+ module RTrail
4
+ describe Result do
5
+ context "Class methods" do
6
+ end
7
+
8
+ context "Instance methods" do
9
+ end
10
+ end
11
+ end # module RTrail
12
+
@@ -0,0 +1,61 @@
1
+ require_relative 'spec_helper'
2
+
3
+ module RTrail
4
+ describe Run do
5
+ context "Class methods" do
6
+ end
7
+
8
+ context "Instance methods" do
9
+ let(:run1) { Run.new(1) }
10
+ let(:run2) { Run.new(2) }
11
+
12
+ describe "#initialize" do
13
+ it "gets the Run data" do
14
+ expect(run1.id).to eq(1)
15
+ expect(run2.id).to eq(2)
16
+ end
17
+ end
18
+
19
+ describe "#summary" do
20
+ it "includes id and name" do
21
+ expect(run1.summary).to include(run1.id.to_s)
22
+ expect(run1.summary).to include(run1.name)
23
+ end
24
+
25
+ it "includes completion status" do
26
+ expect(run1.summary).to include("[completed")
27
+ expect(run2.summary).to include("[not completed")
28
+ end
29
+ end
30
+
31
+ describe "#tests" do
32
+ it "includes all Tests in the Run" do
33
+ expect(run1.tests).to be_an(Array)
34
+ expect(run1.tests.first).to be_a(Test)
35
+ end
36
+ end
37
+
38
+ describe "#complete_time" do
39
+ it "returns a Time if `completed_on` is set" do
40
+ expect(run1.complete_time).to be_a(Time)
41
+ end
42
+
43
+ it "returns nil if `completed_on` is nil" do
44
+ expect(run2.complete_time).to be_nil
45
+ end
46
+ end
47
+
48
+ describe "#completed?" do
49
+ it "returns true if `completed_on` is set" do
50
+ expect(run1.completed?).to be true
51
+ end
52
+
53
+ it "returns false if `completed_on` is nil" do
54
+ expect(run2.completed?).to be false
55
+ end
56
+ end
57
+
58
+ end
59
+ end
60
+ end # module RTrail
61
+
@@ -0,0 +1,19 @@
1
+ require 'simplecov'
2
+ SimpleCov.start if ENV['COVERAGE']
3
+
4
+ PROJECT_ROOT = File.expand_path('..', File.dirname(__FILE__))
5
+ SPEC_DIR = File.join(PROJECT_ROOT, 'spec')
6
+ MOCK_APP_URL = "http://localhost:8080/index.php?/api/v2/"
7
+
8
+ $LOAD_PATH.unshift(File.join(PROJECT_ROOT, 'lib'))
9
+ require 'rtrail'
10
+
11
+ module SpecHelpers
12
+ end
13
+
14
+ RSpec.configure do |config|
15
+ config.include SpecHelpers
16
+ config.before(:all) do
17
+ RTrail::Entity.client = RTrail::Client.new(MOCK_APP_URL, 'user', 'password')
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ require_relative 'spec_helper'
2
+
3
+ module RTrail
4
+ describe Suite do
5
+ context "Class methods" do
6
+ end
7
+
8
+ context "Instance methods" do
9
+ let(:suite) { Suite.new(1) }
10
+
11
+ describe "#sections" do
12
+ let(:sections) { suite.sections }
13
+ it "returns all Sections in the Suite" do
14
+ expect(sections).to be_an(Array)
15
+ expect(sections.first).to be_a(Section)
16
+ end
17
+ end
18
+
19
+ describe "#cases" do
20
+ let(:cases) { suite.cases }
21
+ it "returns all Cases in the Suite" do
22
+ expect(cases).to be_an(Array)
23
+ expect(cases.first).to be_a(Case)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end # module RTrail
29
+
@@ -0,0 +1,34 @@
1
+ require_relative 'spec_helper'
2
+
3
+ module RTrail
4
+ describe Test do
5
+ context "Class methods" do
6
+ end
7
+
8
+ context "Instance methods" do
9
+ let(:test) { Test.new(1) }
10
+
11
+ describe "#results" do
12
+ let(:results) { test.results }
13
+ it "returns all Results for the Test" do
14
+ expect(results).to be_an(Array)
15
+ expect(results.first).to be_a(Result)
16
+ end
17
+ end
18
+
19
+ describe "#latest_result" do
20
+ let(:latest_result) { test.latest_result }
21
+ it "returns the most recent Result for the Test" do
22
+ expect(latest_result).to be_a(Result)
23
+ end
24
+ end
25
+
26
+ describe "#add_result" do
27
+ it "returns a new Result" do
28
+ test.add_result(:status_id => 1)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end # module RTrail
34
+