<commit_before># Ruby::Pretentious

Do you have a pretentious boss or development lead that pushes you to embrace BDD/TDD but for reasons hate it or them?
here is a gem to deal with that. Now you CAN write your code first and then GENERATE tests later!! Yes you heard that
right! To repeat, this gem allows you to write your code first and then automatically generate tests using the code
you've written in a straightfoward manner!

On a serious note, this gem allows you to generate tests template much better than those generated by default
for various frameworks. It is also useful for "recording" current behavior of existing components in order
to prepare for refactoring.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'pretentious'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install pretentious

## Usage

First Create an example file (etc. example.rb) and define the classes that you want to test, if the class is
already defined elsewhere just require them. Below is an example:

```ruby
class Fibonacci

  def fib(n)
    return 0 if (n == 0)
    return 1 if (n == 1)
    return 1 if (n == 2)
    return fib(n - 1) + fib(n - 2)
  end

  def self.say_hello
    "hello"
  end

end
```

Inside a Pretentious.spec_for(...) block. Just write boring code that calls the methods of your class like
how you'd normally use them. Finally Specify the classes that you want to test:

```ruby
class Fibonacci

  def fib(n)
    return 0 if (n == 0)
    return 1 if (n == 1)
    return 1 if (n == 2)
    return fib(n - 1) + fib(n - 2)
  end

  def self.say_hello
    "hello"
  end

end

Pretentious.spec_for(Fibonacci) do


  instance = Fibonacci.new

  (1..10).each do |n|
    instance.fib(n)
  end

  Fibonacci.say_hello

end
```

Save your file and then switch to the terminal to invoke:

    ddtgen example.rb

This will automatically generate rspec tests for Fibonacci under spec of the current working directory.

You can actually invoke rspec at this point, but the tests will fail. Before you do that you should edit
spec/spec_helper.rb and put the necessary requires and definitions there.

For this example place the following into spec_helper.rb:

```ruby
#inside spec_helper.rb

class Fibonacci

  def fib(n)
    return 0 if (n == 0)
    return 1 if (n == 1)
    return 1 if (n == 2)
    return fib(n - 1) + fib(n - 2)
  end

  def self.say_hello
    "hello"
  end

end
```

You can also try this out with build in libraries like MD5 for example

```ruby
#example.rb

Pretentious.spec_for(Digest::MD5) do
  sample = "This is the digest"
  Digest::MD5.hexdigest(sample)
end
```

You should get something like:

```ruby
require 'spec_helper'

RSpec.describe Digest::MD5 do

    it 'should pass current expectations' do

      sample = "This is the digest"

      # Digest::MD5::hexdigest when passed "This is the digest" should return 9f12248dcddeda976611d192efaaf72a
      expect( Digest::MD5.hexdigest(sample) ).to eq("9f12248dcddeda976611d192efaaf72a")

    end
end
```

Only RSpec is supported at this point. But other testing frameworks should be trivial to add support to.

## Things to do after

Since your tests are already written, and hopefully nobody notices its written by a machine, you may just leave it
at that.

But if lest your conscience suffers, it is best to go back to the specs and refine them, add more tests and behave like
a bdd'er/tdd'er.

## Limitations

Computers are bad at mind reading (for now) and they don't really know your expectation of "correctness", as such
it assumes your code is correct and can only use equality based matchers. It can also only reliably match
primitive data types and hashs and arrays to degree. More complex expectations are unfortunately left for the human to resolve.

Also do note that it tries its best to determine how your fixtures are created, as well as the types
of your parameters and does so by figuring out the components that your object needs. Failure can happen during this process.

Finally, Limit this gem for test environments only.

## Bugs

This is the first iteration and a lot of broken things could happen

## Contributing

1. Fork it (https://github.com/jedld/pretentious.git)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request<commit_msg>Readme updates<commit_after># Ruby::Pretentious

Do you have a pretentious boss or development lead that pushes you to embrace BDD/TDD but for reasons hate it or them?
here is a gem to deal with that. Now you CAN write your code first and then GENERATE tests later!! Yes you heard that
right! To repeat, this gem allows you to write your code first and then automatically generate tests using the code
you've written in a straightfoward manner!

On a serious note, this gem allows you to generate tests template much better than those generated by default
for various frameworks. It is also useful for "recording" current behavior of existing components in order
to prepare for refactoring.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'pretentious'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install pretentious

## Usage

First Create an example file (etc. example.rb) and define the classes that you want to test, if the class is
already defined elsewhere just require them. Below is an example:

```ruby
class Fibonacci

  def fib(n)
    return 0 if (n == 0)
    return 1 if (n == 1)
    return 1 if (n == 2)
    return fib(n - 1) + fib(n - 2)
  end

  def self.say_hello
    "hello"
  end

end
```

Inside a Pretentious.spec_for(...) block. Just write boring code that instantiates an object as well as calls the methods
like how you'd normally use them. Finally Specify the classes that you want to test:

```ruby
class Fibonacci

  def fib(n)
    return 0 if (n == 0)
    return 1 if (n == 1)
    return 1 if (n == 2)
    return fib(n - 1) + fib(n - 2)
  end

  def self.say_hello
    "hello"
  end

end

Pretentious.spec_for(Fibonacci) do


  instance = Fibonacci.new

  (1..10).each do |n|
    instance.fib(n)
  end

  Fibonacci.say_hello

end
```

Save your file and then switch to the terminal to invoke:

    ddtgen example.rb

This will automatically generate rspec tests for Fibonacci under spec of the current working directory.

You can actually invoke rspec at this point, but the tests will fail. Before you do that you should edit
spec/spec_helper.rb and put the necessary requires and definitions there.

For this example place the following into spec_helper.rb:

```ruby
#inside spec_helper.rb

class Fibonacci

  def fib(n)
    return 0 if (n == 0)
    return 1 if (n == 1)
    return 1 if (n == 2)
    return fib(n - 1) + fib(n - 2)
  end

  def self.say_hello
    "hello"
  end

end
```

You can also try this out with build in libraries like MD5 for example

```ruby
#example.rb

Pretentious.spec_for(Digest::MD5) do
  sample = "This is the digest"
  Digest::MD5.hexdigest(sample)
end
```

You should get something like:

```ruby
require 'spec_helper'

RSpec.describe Digest::MD5 do

    it 'should pass current expectations' do

      sample = "This is the digest"

      # Digest::MD5::hexdigest when passed "This is the digest" should return 9f12248dcddeda976611d192efaaf72a
      expect( Digest::MD5.hexdigest(sample) ).to eq("9f12248dcddeda976611d192efaaf72a")

    end
end
```

Only RSpec is supported at this point. But other testing frameworks should be trivial to add support to.

## Things to do after

Since your tests are already written, and hopefully nobody notices its written by a machine, you may just leave it
at that. Take note of the limitations though.

But if lest your conscience suffers, it is best to go back to the specs and refine them, add more tests and behave like
a bdd'er/tdd'er.

## Limitations

Computers are bad at mind reading (for now) and they don't really know your expectation of "correctness", as such
it assumes your code is correct and can only use equality based matchers. It can also only reliably match
primitive data types and hashs and arrays to a degree. More complex expectations are unfortunately left for the humans
to resolve.

Also do note that it tries its best to determine how your fixtures are created, as well as the types
of your parameters and does so by figuring out (recursively) the components that your object needs. Failure can happen during this process.

Finally, Limit this gem for test environments only.

## Bugs

This is the first iteration and a lot of broken things could happen

## Contributing

1. Fork it (https://github.com/jedld/pretentious.git)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
{'fraction_non_alphanumeric': 0.06651810584958218, 'fraction_numerical': 0.01604456824512535, 'mean_word_length': 3.622039134912461, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '3241999', 'n_tokens_mistral': 2832, 'n_tokens_neox': 2587, 'n_words': 1335}