<commit_before>Counterfeiter
=============

When writing unit-tests for an object, it is often useful to have fake implementations
of the object's collaborators. In go, such fake implementations cannot be generated
automatically at runtime. This tool allows you to generate them before compiling your code.

### Generating fakes

Choose an interface for which you would like a fake implementation:

```shell
$ cat path/to/some_package/some_interface.go
```

```go
package some_package

type SomeInterface interface {
	DoThings(string, uint64) error
	DoNothing()
}
```

Run counterfeiter like this:

```
$ counterfeiter path/to/some_package SomeInterface
Wrote `FakeSomeInterface` to `path/to/some_package/fakes/fake_some_interface.go`
```

You can customize the location of the ouptut using the `-o` flag, or write the code to standard out by providing `-` as a third argument.

### Using the fake in your tests

Fake objects record their calls:

```go
fake := new(fakes.FakeSomeInterface)

fake.DoThings("stuff", 5)

Expect(fake.DoThingsCalls()).To(HaveLen(1))
Expect(fake.DoThingsCalls()[0].Arg1).To(Equal("stuff"))
Expect(fake.DoThingsCalls()[0].Arg2).To(Equal(uint64(5)))
```

You can set their return values:

```go
fake.DoThingsReturns(errors.New("the-error"))

Expect(fake.DoThings("stuff", 5)).To(Equal(errors.New("the-error")))
```

You can also supply them with stub functions:

```go
fake.DoThingsStub = func(arg1 string, arg2 uint64) error {<commit_msg>Add import to example code in README<commit_after>Counterfeiter
=============

When writing unit-tests for an object, it is often useful to have fake implementations
of the object's collaborators. In go, such fake implementations cannot be generated
automatically at runtime. This tool allows you to generate them before compiling your code.

### Generating fakes

Choose an interface for which you would like a fake implementation:

```shell
$ cat path/to/some_package/some_interface.go
```

```go
package some_package

type SomeInterface interface {
	DoThings(string, uint64) error
	DoNothing()
}
```

Run counterfeiter like this:

```
$ counterfeiter path/to/some_package SomeInterface
Wrote `FakeSomeInterface` to `path/to/some_package/fakes/fake_some_interface.go`
```

You can customize the location of the ouptut using the `-o` flag, or write the code to standard out by providing `-` as a third argument.

### Using the fake in your tests

Fake objects record their calls:

```go
import "my-repo/path/to/some_package/fakes"

// ...

fake := new(fakes.FakeSomeInterface)

fake.DoThings("stuff", 5)

Expect(fake.DoThingsCalls()).To(HaveLen(1))
Expect(fake.DoThingsCalls()[0].Arg1).To(Equal("stuff"))
Expect(fake.DoThingsCalls()[0].Arg2).To(Equal(uint64(5)))
```

You can set their return values:

```go
fake.DoThingsReturns(errors.New("the-error"))

Expect(fake.DoThings("stuff", 5)).To(Equal(errors.New("the-error")))
```

You can also supply them with stub functions:

```go
fake.DoThingsStub = func(arg1 string, arg2 uint64) error {
{'fraction_non_alphanumeric': 0.1264138389886893, 'fraction_numerical': 0.010645375914836993, 'mean_word_length': 5.494600431965443, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1282226', 'n_tokens_mistral': 979, 'n_tokens_neox': 910, 'n_words': 304}