Skip to content

Commit

Permalink
preparing plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriomazzeo committed Aug 1, 2016
1 parent bbb3ee8 commit 416a9a5
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 51 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016 Valerio Mazzeo <[email protected]>
Copyright (c) 2016 Valerio Mazzeo

MIT License

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# danger-xcodebuild

A description of danger-xcodebuild.
Exposes warnings, errors and test results. It requires a JSON generated using [xcpretty-json-formatter](https://github.com/marcelofabri/xcpretty-json-formatter), to be passed as an argument for it to work.

## Installation

Expand Down
7 changes: 0 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'

RSpec::Core::RakeTask.new(:specs)

task default: :specs

task :spec do
Rake::Task['specs'].invoke
Rake::Task['rubocop'].invoke
Rake::Task['spec_docs'].invoke
end

desc 'Run RuboCop on the lib/specs directory'
RuboCop::RakeTask.new(:rubocop) do |task|
task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
end

desc 'Ensure that the plugin passes `danger plugins lint`'
task :spec_docs do
sh 'bundle exec danger plugins lint'
Expand Down
7 changes: 3 additions & 4 deletions danger-xcodebuild.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
spec.version = Xcodebuild::VERSION
spec.authors = ['Valerio Mazzeo']
spec.email = ['[email protected]']
spec.description = %q{A short description of danger-xcodebuild.}
spec.summary = %q{A longer description of danger-xcodebuild.}
spec.homepage = 'https://github.com/Valerio Mazzeo/danger-xcodebuild'
spec.description = %q{Exposes warnings, errors and test results.}
spec.summary = %q{Exposes warnings, errors and test results. It requires a JSON generated using xcpretty-json-formatter to be passed as an argument for it to work.}
spec.homepage = 'https://github.com/valeriomazzeo/danger-xcodebuild'
spec.license = 'MIT'

spec.files = `git ls-files`.split($/)
Expand All @@ -28,7 +28,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rspec', '~> 3.4'

# Linting code and docs
spec.add_development_dependency "rubocop", "~> 0.41"
spec.add_development_dependency "yard", "~> 0.8"

# Makes testing easy via `bundle exec guard`
Expand Down
68 changes: 48 additions & 20 deletions lib/xcodebuild/plugin.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,61 @@
module Danger
# This is your plugin class. Any attributes or methods you expose here will
# be available from within your Dangerfile.
# Exposes warnings, errors and test results.
# It requires a JSON generated using [xcpretty-json-formatter](https://github.com/marcelofabri/xcpretty-json-formatter),
# to be passed as an argument for it to work.
#
# To be published on the Danger plugins site, you will need to have
# the public interface documented. Danger uses [YARD](http://yardoc.org/)
# for generating documentation from your plugin source, and you can verify
# by running `danger plugins lint` or `bundle exec rake spec`.
# @example Ensure the project compiles without warnings, errors and all tests are executed correctly
#
# You should replace these comments with a public description of your library.
# xcodebuild.parse_warnings
# xcodebuild.parse_errors
# xcodebuild.parse_tests
#
# @example Ensure people are well warned about merging on Mondays
#
# my_plugin.warn_on_mondays
#
# @see Valerio Mazzeo/danger-xcodebuild
# @tags monday, weekends, time, rattata
# @see valeriomazzeo/danger-xcodebuild
# @tags xcode, xcodebuild, errors, warnings, tests, xcpretty-json-formatter
#
class DangerXcodebuild < Plugin

# An attribute that you can read/write from your Dangerfile
# Allows you to specify an xcodebuild JSON file location to parse.
attr_accessor :xcodebuild_json

def initialize
@warning_count = 0
@error_count = 0
@test_failures_count = 0
end

# Parses and exposes eventual warnings.
# @return [warning_count]
#
# @return [Array<String>]
attr_accessor :my_attribute
def parse_warnings

# A method that you can call from your Dangerfile
# @return [Array<String>]
end

# Parses and expose eventual errors.
# @return [error_count]
#
def warn_on_mondays
warn 'Trying to merge code on a Monday' if Date.today.wday == 1
def parse_errors

end

# Parses and exposes eventual test failures.
# @return [test_failures]
#
def parse_tests

end

# Prints "Perfect build πŸ‘πŸ»" if everything is ok after parsing.
# @return [is_perfect_build]
#
def perfect_build
is_perfect_build = @warning_count == 0 && @errors.count == 0 && @test_failures.count == 0
message("Perfect build πŸ‘πŸ»") if is_perfect_build
return is_perfect_build
end
end

def self.instance_name
to_s.gsub("Danger", "").danger_underscore.split("/").last
end
end
end
22 changes: 4 additions & 18 deletions spec/xcodebuild_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,17 @@ module Danger
describe 'with Dangerfile' do
before do
@dangerfile = testing_dangerfile
@my_plugin = @dangerfile.my_plugin
@xcodebuild = @dangerfile.xcodebuild
end

# Some examples for writing tests
# You should replace these with your own.

it "Warns on a monday" do
it "is a perfect build" do
monday_date = Date.parse("2016-07-11")
allow(Date).to receive(:today).and_return monday_date

@my_plugin.warn_on_mondays

expect(@dangerfile.status_report[:warnings]).to eq(["Trying to merge code on a Monday"])
end

it "Does nothing on a tuesday" do
monday_date = Date.parse("2016-07-12")
allow(Date).to receive(:today).and_return monday_date

@my_plugin.warn_on_mondays

expect(@dangerfile.status_report[:warnings]).to eq([])
expect(@xcodebuild.perfect_build).to be_true
expect(@dangerfile.status_report[:messages]).to eq(["Perfect build πŸ‘πŸ»"])
end

end
end
end

0 comments on commit 416a9a5

Please sign in to comment.