Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a CocoaPods plugin #25

Merged
merged 1 commit into from
Oct 7, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,9 @@ after_success: slather

### Coverage for code included via CocoaPods

If you're trying to compute the coverage of code that has been included via CocoaPods, you can add the following to your Podfile:

```ruby
# Podfile

begin
require 'slather'
Slather.prepare_pods(self)
rescue LoadError
puts 'Slather has been disabled (not installed).'
end
```

Then, tell slather where to find the source files for your Pod.
If you're trying to compute the coverage of code that has been included via
CocoaPods, you will need to tell slather where to find the source files for
your Pod.

```yml
# .slather.yml
Expand Down
10 changes: 10 additions & 0 deletions lib/cocoapods_plugin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'slather'

Pod::HooksManager.register(:post_install) do |installer_context|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, as long as someone has slather installed, this will run after a pod install?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's right

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is super awesome!

sandbox_root = installer_context.sandbox_root
sandbox = Pod::Sandbox.new(sandbox_root)
project = Xcodeproj::Project.open(sandbox.project_path)
project.slather_setup_for_coverage()
project.save()
end

4 changes: 1 addition & 3 deletions lib/slather.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ module Slather
Encoding.default_external = "utf-8"

def self.prepare_pods(pods)
pods.post_install do |installer|
installer.project.slather_setup_for_coverage
end
Pod::UI.warn("[Slather] prepare_pods is now deprecated. The call to prepare_pods in your Podfile can simply be ommitted.")
end

end
1 change: 1 addition & 0 deletions slather.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rake", "~> 10.3"
spec.add_development_dependency "rspec", "~> 2.14"
spec.add_development_dependency "pry", "~> 0.9"
spec.add_development_dependency "cocoapods", "~> 0.34"

spec.add_dependency "clamp", "~> 0.6"
spec.add_dependency "xcodeproj", "~> 0.17"
Expand Down
21 changes: 21 additions & 0 deletions spec/slather/cocoapods_plugin_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'cocoapods'
require File.join(File.dirname(__FILE__), '../../lib/cocoapods_plugin')
require File.join(File.dirname(__FILE__), '..', 'spec_helper')

describe Slather do
describe 'CocoaPods Plugin' do
it 'should setup slather for coverage in the Pods project' do
mock_project = double(Xcodeproj::Project)
allow(Xcodeproj::Project).to receive(:open).and_return(mock_project)
expect(mock_project).to receive(:slather_setup_for_coverage)
expect(mock_project).to receive(:save)

# Execute the post_install hook via CocoaPods
sandbox_root = 'Pods'
sandbox = Pod::Sandbox.new(sandbox_root)
context = Pod::Installer::HooksContext.generate(sandbox, [])
Pod::HooksManager.run(:post_install, context)
end
end
end

19 changes: 0 additions & 19 deletions spec/slather/slather_spec.rb

This file was deleted.